thinkphp如何隐藏index.php

Home / Article MrLee 2014-10-9 2788

下面我来给大家介绍在nginx或iis环境中把index.php文件给隐藏掉了,就是在访问页面时不显示index.php文件,这个据说对网站优化有好处。 例如你的原路径是 http://localhost/test/index.php/index/add 那么现在的地址是 http://localhost/test/index/add 如何去掉index.php呢?
IIS环境 如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容: 代码如下 复制代码 RewriteRule (.*)$ /index.php?s=$1 [I] 在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点: 代码如下 复制代码
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;}}
apache环境 1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置 #LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉 2.AllowOverride None 讲None改为 All//在APACHE里面去配置 (注意其他地方的AllowOverride也统统设置为ALL) 代码如下 复制代码 AllowOverride none 改AllowOverride ALL Options None Order allow,deny Allow from all 3.确保URL_MODEL设置为2,在项目的配置文件里写 代码如下 复制代码 return Array('URL_MODEL' => '2', ); 4 .htaccess文件必须放到跟目录下 这个文件里面加: 代码如下 复制代码 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件 然后在DOS在操作 rename xxxx.xxxx.htaccess

本文链接:https://www.it72.com/196.htm

推荐阅读
最新回复 (0)
返回