【发布时间】:2016-08-30 01:44:53
【问题描述】:
我正在尝试从 Apache + mod_php 迁移到 Nginx + PHP-FPM。我目前正在使用mod_rewrite 将一些以.php 结尾的虚拟URI 重写为实际的PHP 脚本。这在使用mod_php 时非常有效。但是使用Nginx + FPM,因为我们必须使用proxy_pass,所以这是行不通的。当我添加一个正则表达式位置块以匹配 .php 扩展名时,它获得最高优先级,并且我的重写规则不适用。
我该如何解决这个问题?
location /test/ {
rewrite "^/test/([a-z]+).php$" test.php?q=$1 last;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $fastcgi_script_name_custom $fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
set $fastcgi_script_name_custom "/cms/index.php";
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
【问题讨论】:
标签: php nginx url-rewriting