CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样http://localhost/CodeIgniter/index.php/welcome。不太好看,怎么把其中的index.php取掉呢?
解决方法如下:
去掉 URL 中的 index.php
首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite,并且已经配置好 rewrite 相关的参数。 什么是 rewrtie 可以 Google 一下。 然后,在 CI 根目录下新建立一个配置文件,命名为: .htaccess 在里面这样写:
TEXT
RewriteEngine on
RewriteCond $1 !^(index/.php|images|robots/.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
TEXT
RewriteCond $1 !^(index/.php|images|robots/.txt)
哦,对了,还要修改 config.php 这个文件中的下列内容:
PHP
/*
|-------------------------------------------------------------------------- | Index File |-------------------------------------------------------------------------- | | Typically this will be your index.php file, unless you've renamed it to | something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ $config [ 'index_page' ] = "index.php" ; |