Nginx服務(wù)器默認不支持pathinfo, 在需要pathinfo支持的程序中(如laravel,TP),則無法支持”/index.php/Home/Index/index”這種網(wǎng)址.
要是我們的網(wǎng)站支持Pathinfo模式的路由件已,可采用以下配置:
修改之前:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include snippets/fastcgi-php.conf;
}
修改之后:
location ~ \.php(.*)$ { # 正則匹配.php后的pathinfo部分
fastcgi_pass 127.0.0.1:9000;
include snippets/fastcgi-php.conf;
fastcgi_param PATH_INFO $1; # 把pathinfo部分賦給PATH_INFO變
}
如果還需要隱藏我們的入口文件(一般為index.php)芭挽,那么在添加以下配置即可:
location / {
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}