原文地址:http://www.nowamagic.net/php/php_RemoveIndexInCi.php
CI默认的rewrite url中是类似这样的,
例如你的CI根目录是在/CodeIgniter/下,
你的下面的二级url就类似这样
http://localhost/CodeIgniter/index.php/welcome。
不太好看,怎么把其中的index.php取掉呢?
1. 打开apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so,
把该行前的#去掉。
搜索 AllowOverride None(配置文件中有多处),
看注释信息,将相关.htaccess的该行信息改为AllowOverride All。(ctrl+F 找一下 目测是第二个...)
2. 在CI的根目录下,即在index.php,system的同级目录下,
建立.htaccess,内容如下(CI手册上也有介绍):
RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目录下,例如我的是:
http://www.nowamagic.net/CodeIgniter/,
第三行需要改写为
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。
另外,我的index.php的同级目录下还有js文件夹和css文件夹,
这些需要过滤除去,第二行需要改写为:RewriteCond $1
!^(index\.php|images|js|css|robots\.txt)
关于如何新建.htaccess文件,我的方法是,打开EditPlus或者nodepad++,直接编写后保存为.htaccess
3.将CI中配置文件(system/application/config/config.php)中
$config['index_page'] = "index.php";
改为
$config['index_page'] = ""; 。
ok,完成。还要记得重启apache。
那么在SAE里面如何隐藏index.php呢?
第一步:修改项目根目录的config.yaml文件,添加如下内容:
handle: - rewrite: if(!is_dir() && !is_file() && path~"/") goto "/index.php/%{QUERY_STRING}"
第二步:将application/config/config.php中的$config['index_page']设置为'':
$config['index_page'] = '';