![](/img/trans.png)
[英]mod_redirect every request except a.php, b.php and c.php
[英]how to nginx rewrite a.php,b.php,c.php to /index.php
这是我的重写代码:
location / {
if (!-e $request_filename){
rewrite "(*UTF8)^/(.*)$" / last;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
}
我想将a.php,b.php,c.php重写为/index.php。但是不起作用!但是当我键入a。,bc时,上面的代码可以工作,我弄错了吗?
您当前的问题是任何带有.php
URI都由PHP位置块处理,因此绕过了重写规则。 在/
位置和PHP位置都使用try_files
。 例如:
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
}
有关更多信息,请参见此文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.