ThinkPHP -- 去除URL中的index.php

  • 原路径是 http://localhost/test/index.php/index/add
  • 想获得的地址是 http://localhost/test/index/add
  • 那么如何去掉index.php呢? @_@!!
 
(1)apache 设置
  •   httpd.conf配置文件中加载了mod_rewrite.so模块 
LoadModule rewrite_module modules/mod_rewrite.so
  • AllowOverride None 讲None改为 All
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

 

(2)确保URL_MODEL设置为2,在项目的配置文件config.php里

return Array(
      ……
    'URL_MODEL' => '2',
      ……
);

 

(3)添加.htaccess文件,并添加如下代码,必须放到项目根目录下

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
 
补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件

然后在DOS在操作 rename xxxx.xxxx .htaccess

或者打开记事本写入htaccess然后另存为.htaccess即可

如果出现403错误则将.htaccess打开在开头添加Options +FollowSymLinks
 
即如下所示:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

即可解决。
无权限也是加上Options +FollowSymLinks

 
posted @ 2013-10-15 12:42  lmei  阅读(624)  评论(0编辑  收藏  举报