php技术博客
让天下没有搞不定的bug~

thinkphp如何隐藏index.php之IIS和nginx

前天小涛简单的说了一下thinkphp在apache环境下是如何隐藏index.php的,为了更好的实现SEO优化,今天小涛在说一下在iis和nginx环境下是如何隐藏index.php的:

IIS环境
如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

RewriteRule (.*)$ /index\.php\?s=$1 [I]

在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

lt;rewrite> <rules> <rule name=”OrgPage” stopProcessing=”true”> <match url=”^(.*)$” /> <conditions logicalGrouping=”MatchAll”> <add input=”{HTTP_HOST}” pattern=”^(.*)$” /> <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” /> <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” /> </conditions> <action type=”Rewrite” url=”index.php/{R:1}” /> </rule> </rules> </rewrite&gt

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

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

}
}

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

到这里不管什么环境下,都可以实现隐藏index.php的目的了,这样就可以根据自己的需求的随心所欲了,哈哈……

技术分享,技术交流,小涛与您共同成长……

 

 
赞(0)
未经允许不得转载:PHP技术博客 » thinkphp如何隐藏index.php之IIS和nginx