时时商务社区
标题:
让Nginx支持ThinkPHP的URL重写和PATHINFO的方法分享
[打印本页]
作者:
wx_pylelnL4
时间:
2018-2-14 08:39
网上搜了很多方法都不奏效,研究了一天,发现通过以下的配置可以完美支持 'URL_MODEL' => 2 的情况了
[U]复制代码[/U] 代码如下:
location /project/ {
index index.php;
if (!-e $request_filename) {
rewrite ^/project/(.*)$ /project/index.php/$1 last;
break;
}
}
location ~ .+\.php($|/) {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php?IF_REWRITE=1;
include /APMServ/nginx/conf/fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}
这里先把project下的请求都转发到index.php来处理,亦即ThinkPHP的单一入口文件;然后把对php文件的请求交给fastcgi来处理,并且添加对PATH_INFO的支持。
重启Nginx以后,http://localhost/project/Index/insert, http://localhost/project/index.php/Index/delete 这样的URL都可以正确访问了。
还有一个地方需要注意的是,Nginx配置文件里 if 和后面的括号之间要有一个空格,不然会报unknown directive错误。
您可能感兴趣的文章:
在nginx中配置pathinfo模式支持thinkphp的URL重写
Nginx隐藏index.php和Pathinfo模式配置例子
nginx支持codeigniter的pathinfo模式url重写配置写法示例
nginx中配置pathinfo模式示例
lnmp环境中如何为nginx开启pathinfo
nginx+thinkphp下解决不支持pathinfo模式
Ubuntu下Nginx配置ThinkPHP的Pathinfo和URl Rewrite模式
Nginx配置PATHINFO隐藏thinkphp index.php
Nginx下配置pathinfo及ThinkPHP的URL Rewrite模式支持
解决nginx不支持thinkphp中pathinfo的问题
thinkphp在低版本Nginx 下支持PATHINFO的方法分享
nginx配置支持php的pathinfo模式配置方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2