我有以下NGINX重写规则这对于安装在一个子文件夹一个PHP脚本的伟大工程:
I have the following NGINX rewrite rule which works great for a PHP script installed in a subfolder:
location /subfolder/ {
if (!-e $request_filename){
rewrite ^/subfolder/(.*) /subfolder/index.php?do=/$1;
}
}
但Nginx的维基说,使用如果是邪恶 http://wiki.nginx.org/IfIsEvil所以我尝试了以下
location /subfolder/ {
try_files $uri $uri/ /subfolder/index.php?$args;
}
,但它不工作来代替上述之一,然而它可以用于字preSS和大部分的PHP脚本。如果有一种方法来翻译它使用try_files?
but it doesn't work to replace the one above, although it works for WordPress and most of the PHP scripts. If there a way to translate it to use "try_files"?
感谢您!
您想做的重写仅在文件不存在,把它作为在 try_files回退命名位置
You want to do the rewrite only if the file doesn't exist, use it as a named location for the fall back in try_files
location /subfolder {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/subfolder/(.*) /subfolder/index.php?do=/$1;
}