我的 nginx 虚拟主机文件中有这个指令:
try_files $uri $uri/ /profile.php?nickname=$uri&$args;
它工作正常,但我只想重写 0-9a-z- 字符,以便用户有很好的个人资料地址,例如:
http://www/mydomain.com/john
但是 nginx 重写了一切。例如,如果我输入地址:
http://www.mydomain.com/non-existing-holder/nonexisting-filename.html
它不会返回 404 错误,而是重写所有内容。
有没有办法只重写 0-9-az- 字符?
server {
listen 80;
server_name www.mydomain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/mydomain;
error_page 404 /4044.html;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /profile.php?nickname=$uri&$args;
rewrite ^/forum/([0-9-]+)/([0-9a-z-]+).html$ /forum.php?tid=$1&title=$2 last;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}