我在将 htaccess 文件中的重写代码实现到 nginx 配置中时遇到问题。
我已经尝试过生成器:http://winnginx.com/htaccess http://winginx.com/htaccess用于生成我的重写
代码。
我的nginx配置代码:
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;
}
}
我想从我的 .htaccess 实现这个:
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;
}
我已经尝试将最后几行代码实现到我的位置块,但根本不起作用。
我将非常感谢每一个意见!
问候
马克罗马特
盲目的转换是
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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)