【发布时间】:2016-04-24 18:53:43
【问题描述】:
您好,我正在尝试正确设置 mod_rewrite,我对 lighttpd 没有任何问题,但我也想交换 nginx。
location /highscores {
rewrite ^/highscores /?page=highscores last;
}
location /highscores/ {
rewrite ^/highscores/(.*)/(.*)$ /?page=highscores&list=$1&page=$2 last;
}
问题是,如果你输入诸如 /highscores/ 之类的方向,最后 / 会出现错误 404,如果你尝试 /highscores/example 也会出现 404,但 /highscores/example/ 工作正常,有没有人能解决这个问题?
我在谷歌上找不到解决方案。
配置
server {
listen 80;
server_name example.com;
root /usr/share/nginx/www/example.com;
include /etc/nginx/include.d/all-common;
include /etc/nginx/include.d/example.com;
}
通用
index index.php index.html index.htm;
try_files $uri $uri/ /index.html;
location / {
try_files $uri $uri/ = /;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
include.d 中的 example.com 有我粘贴在顶部的其余代码
【问题讨论】:
-
正则表达式
^/highscores/(.*)/(.*)$既不匹配/highscores/也不匹配/highscores/example因此此重写不适用。你期待什么重写? -
另外,我很好奇,你为什么要两个
page参数? -
我只需要一个,但它根本不起作用。 example.com/highscores 显示 404 example.com/highscores/ 显示 404 example.com/highscores/example 正在工作,但不应该,它显示错误的 parm list=$1
-
@Edited 我添加了完整配置
标签: mod-rewrite nginx