Nginx支持ThinkPHP的url rewrite到index.php

形如 http://test.com/index.php/s/asdf 或者 http://test.com/s/asdf 的链接在ThinkPHP中很常见,有的nginx环境中会无法正常解析,而是输出不带任何参数的index.php。

需要在conf中增加

fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

这样,完整的此部分配置可能为:

location ~ \.php/?.*$ {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO  $fastcgi_path_info;
fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
include fastcgi_params;

文章原始链接:https://sijie.wang/posts/nginx-think-php-rewrite/

本站文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请保留原始链接