我需要在 nginx 服务器中制定 url 重写规则(服务器块),就像我之前的 apache 服务器一样。
这是 .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]
这段代码位于我的网站中,因为我需要隐藏在登录后文件所在的地址栏文件夹(/admin/)中。当有人已经登录时,地址栏就像www.domain.com/用户名当你点击菜单地址时就像www.domain.com/用户名/page1, www.domain.com/用户名/page2, www.domain.com/用户名/page3。
这就是我需要在nginx中实现的。因为现在是完整的后端,没有功能。当我登录后端时,我被重定向到www.domain.com/用户名但在屏幕上我只能看到文件未找到。仅当我手动添加时才在后端工作www.domain.com/admin/index.php.
这是我的 nginx 实际配置:
server_names_hash_bucket_size 64;
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;
location / {
rewrite ^([^\.]*)$ /$1.php;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
当我尝试将我的块更改为:
location / {
rewrite ^([^\.]*)$ /$1.php;
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;
}
我的每个 css 文件都有错误 500...
如果有任何帮助,我将非常感激!
多谢。
您将其放入您的 / 位置,这意味着您的所有请求在您放到此处之前均不匹配。您必须在位置/之前创建特定于此条目的位置角色
location ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ {
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)