Apache 将代码从htaccess重写到nginx config?
我在将代码从htaccess文件重写到nginx config时遇到问题。 我已经尝试了生成器:用于生成我的重写 代码 我的nginx配置代码:Apache 将代码从htaccess重写到nginx config?,apache,.htaccess,mod-rewrite,nginx,Apache,.htaccess,Mod Rewrite,Nginx,我在将代码从htaccess文件重写到nginx config时遇到问题。 我已经尝试了生成器:用于生成我的重写 代码 我的nginx配置代码: server { listen 80; server_name example.com; return 301 $scheme://www.example.com$request_uri; } server { listen 80; root /usr/sh
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name www.example.com;
error_page 404 http://www.example.com/404.php;
autoindex off;
error_log /usr/share/nginx/www/nginx_error.log warn;
location / {
rewrite ^([^\.]*)$ /$1.php;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2 [QSA]
RewriteRule ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 [L]
location / {
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2;
rewrite ^/(([A-Za-z0-9-/]+)+)$ /admin/index.php?hotelname=$1 break;
}
我想从我的.htaccess:
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name www.example.com;
error_page 404 http://www.example.com/404.php;
autoindex off;
error_log /usr/share/nginx/www/nginx_error.log warn;
location / {
rewrite ^([^\.]*)$ /$1.php;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2 [QSA]
RewriteRule ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 [L]
location / {
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2;
rewrite ^/(([A-Za-z0-9-/]+)+)$ /admin/index.php?hotelname=$1 break;
}
从工具生成的代码:
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name www.example.com;
error_page 404 http://www.example.com/404.php;
autoindex off;
error_log /usr/share/nginx/www/nginx_error.log warn;
location / {
rewrite ^([^\.]*)$ /$1.php;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2 [QSA]
RewriteRule ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 [L]
location / {
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2;
rewrite ^/(([A-Za-z0-9-/]+)+)$ /admin/index.php?hotelname=$1 break;
}
我已经尝试将这最后几行代码实现到我的位置块,但根本不起作用。。
我将非常感谢每一个意见!
当做
Makromat这种盲转换是
rewrite ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2&$query_string last;
rewrite ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 last;
但我更希望我能更理解这个问题,从而产生一个更优化的重写
我什么时候知道URL是否应该传递给
/admin
,给我一个后端和前端的实际URI。通常使用nginx的思维方式在nginx中更好地管理重写。而这种新的思维方式更是基于
因此,您可以尝试类似的方法(未经测试):
如果不应该直接访问给定的$uri
,则从try\u文件中删除该部分。现在我也不确定您的第二个正则表达式([A-Za-z0-9-/]+)+)
,为什么不使用:
location ^~ "/([A-Za-z0-9-/])+"
或
因此,即使在您的apache重写中,也可能有我看不到的东西。Hello@DanFromGermany您可以在那里看到更好的描述:您知道吗?在原始
.htaccess
中,与url重写相关的其他行是什么?任何RewriteBase
例如?我的skype是matej.marko7请邀请我谢谢!一个解决方案将更容易,最终的代码将被上传。现在我有内部服务器错误500对每个文件(css,图像),但php是加载。但其他一切都和以前一样。(当我登录时,页面被重定向到,浏览器中只有“找不到文件”)我认为这是一种不好的做法,如果我进入domain.com/abc
,应用程序如何知道abc
是页面还是用户名?在博客[at]abushady[dot]com
上给我发电子邮件,这样你就不会在这里发布你的域名了