这是我的重写代码:
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。但它不起作用!但是当我输入。,bc,上面的代码可以工作时,我做错了?
答案 0 :(得分:0)
您当前的问题是任何带有.php
的URI都由PHP位置块处理,因此会绕过您的重写规则。在try_files
位置和PHP位置使用/
。例如:
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/";
}
有关详情,请参阅this document。