最近在用thinkphp做一個項目,基本完成后部署到nginx服務器上才發(fā)覺nginx是不支持pathinfo的那么我們?nèi)绾蝸硖幚砟亍?/P>
Nginx環(huán)境
在Nginx低版本中,是不支持PATHINFO的,但是可以通過在Nginx.conf(在/usr/local/nginx/conf/nginx.conf或者通過find / | grep nginx.conf來查找位置)中配置轉發(fā)規(guī)則實現(xiàn):在nginx配置文件中添加:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
其實內(nèi)部是轉發(fā)到了ThinkPHP提供的兼容模式的URL,利用這種方式,可以解決其他不支持PATHINFO的WEB服務器環(huán)境。
如果你的ThinkPHP安裝在二級目錄,Nginx的偽靜態(tài)方法設置如下,其中youdomain是所在的目錄名稱。
location /youdomain/ {
if (!-e $request_filename){
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last;
}
}
如:
location /thinkphp/ {
if (!-e $request_filename){
rewrite ^/thinkphp/(.*)$ /thinkphp/index.php?s=$1 last;
}
}
語法:rewrite regex replacement flag (last 相當于apache里面的[L]標記,表示rewrite。)