nginx环境下thinkphp添加对 pathinfo的支持

作者

早接触pathinfo,是在使用thinkphp做url重写的时候遇到的。phpinfo 不是thinkphp独有的,甚至也不是php独有的。基本的应该说 pathifo是一种cgi标准。可以简单的理解成 PATHINOF提供了一个虚拟的路径,说是虚拟的因为,服务器中可能没有具体的这个路径。比如 /index.php/c/a/s.html服务器中没有一个文件夹的名字是 index.php ,并且 index.php 目录下有个目录c ...

cgi标准对对PATH_INFO的格式规定

      PATH_INFO = "" | ( "/" path )
      path      = lsegment *( "/" lsegment )
      lsegment  = *lchar
      lchar     = <any TEXT or CTL except "/">

nginx thinkphp的pathinfo 配置
nginx thinkphp的pathinfo 配置

https://tools.ietf.org/html/rfc3875#page-13 英文不好,看了个大概。大概意思说的是 pathinfo 有cgi脚本通过解析URI产生的。解析的基本方法就是两个 / 之间的是参数而不是真实的路径并且是在 SCRIPT_NAME 之后的
比如 : URI: /index.php/c/a/s.html 的pathinfo 就是 /c/a/s.html

    location ~ \.php {
        fastcgi_param  PHP_VALUE  "open_basedir=$document_root:/tmp/";
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

# nginx 添加对 pathinfo 的支持
        set $path_info "";
        if ($uri ~ \.php(/.+) ) {
            set $path_info $1;
        }
        fastcgi_param PATH_INFO $path_info;

        include        fastcgi_params;
    }

回复

您的电子邮箱地址不会被公开。