lnmp开启pathinfo,支持index.php/xx/xx这种脑残URL

来自:互联网
时间:2020-04-15
阅读:

有些程序的URL是www.xxoo.com/index.php/xx/xx/这种模式,典型thinkphp爱用的脑残URL模式。lnmp环境默认是不支持,打开会显示404,需要lnmp支持pathinfo。

找到虚拟主机对应的xxoo.conf文件,找到:

location ~ [^/].php(/|$)
{
    # comment try_files $uri =404; to enable pathinfo
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include pathinfo.conf;
}

替换成:

if (!-e $request_filename)
{
    rewrite ^/([^.]*)$ /index.php/$1 last;
    break;
    }
    location ~ .php
    {
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    set $path_info "";
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
    }
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;
}

然后重启Nginx即可。

返回顶部
顶部