本教程操作环境:windows7系统、thinkphp v6版,该方法适用于所有品牌电脑。
推荐:《php视频教程》《thinkphp教程》
thinkphp隐藏index.php
为了更好的实现seo优化,我们需要隐藏url地址中的index.php,由于不同的服务器环境配置方法区别较大,apache环境下面的配置我们可以参考5.9 url重写来实现,就不再多说了,这里大概说明下iis和nginx下面的基本配置方法和思路.
iis环境
如果你的服务器环境支持isapi_rewrite的话,可以配置httpd.ini文件,添加下面的内容:
rewriterule (.*)$ /index\.php\?s=$1 [i]
在iis的高版本下面可以配置web.config,在中间添加rewrite节点:
name="orgpage" stopprocessing="true">url="^(.*)$" />logicalgrouping="matchall">input="{http_host}" pattern="^(.*)$" />input="{request_filename}" matchtype="isfile" negate="true" />input="{request_filename}” matchtype="isdirectory" negate="true" />type="rewrite" url="index.php/{r:1}" />
nginx环境
在nginx低版本中,是不支持pathinfo的,但是可以通过在nginx.conf中配置转发规则实现:
location / { // …..省略部分代码if (!-e $request_filename) {rewrite ^(.*)$ /index.php?s=$1 last;break;}}
其实内部是转发到了thinkphp提供的兼容模式的url,利用这种方式,可以解决其他不支持pathinfo的web服务器环境,如果你的thinkphp安装在二级目录,nginx的伪静态方法设置如下,其中youdomain是所在的目录名称.
location /youdomain/ {if (!-e $request_filename){rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last;}}
以上就是thinkphp index.php隐藏的方法的详细内容。
