CI默认的rewrite url中是相似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就相似这样http://localhost /CodeIgniter/index.php/welcome。不太好看,怎么把其中的index.php取掉呢?php
1. 打开apache的配置文件,conf/httpd.conf :css
LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。apache
搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改成AllowOverride All。app
2. 在CI的根目录下,即在index.php,system的同级目录下,创建.htaccess,直接创建该文件名的不会成功,能够先创建记事本文件,另存为该名的文件便可。内容以下(CI手册上也有介绍):less
1 RewriteEngine on 2 RewriteCond $1 !^(index\.php|images|robots\.txt) 3 RewriteRule ^(.*)$ /index.php/$1 [L]
若是文件不是在www的根目录下,例如个人是:http://www.nowamagic.net/CodeIgniter/,第三行须要改写为RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。ide
另外,个人index.php的同级目录下还有js文件夹和css文件夹,这些须要过滤除去,第二行须要改写为:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)this
3.将CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。url
01 /* 02 |-------------------------------------------------------------------------- 03 | Index File 04 |-------------------------------------------------------------------------- 05 | 06 | Typically this will be your index.php file, unless you've renamed it to 07 | something else. If you are using mod_rewrite to remove the page set this 08 | variable so that it is blank. 09 | 10 */ 11 $config['index_page'] = '';
ok,完成。还要记得重启apache。spa
就这么简单,好好体验CI吧~.net