ThinkPHP 在nginx环境下去掉URL中的index.php

时间:2021-01-16 19:59:09

在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:


location /{// …..省略部分代码
if(!-e $request_filename){
rewrite^(.*)$/index.php?s=$1last;
break;
}

其实内部是转发到了ThinkPHP提供的兼容模式的URL,利用这种方式,可以解决其他不支持PATHINFO的WEB服务器环境。

如果你的ThinkPHP安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

location /youdomain/{
if(!-e $request_filename){
rewrite^/youdomain/(.*)$/youdomain/index.php?s=$1last;
}
}

本文出自 “Centi.Linux” 博客,请务必保留此出处http://centilinux.blog.51cto.com/1454781/1265218