CI 框架移除index.php
1.Apache开启 mod_rewrite 扩展
找到配置文件httpd.conf,找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉,如果没有则需要添加LoadModule rewrite_module modules/mod_rewrite.so
2.配置.htaccess文件
进入到CI根目录,新建.htaccess文件,输入
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/
1
[
L
]
如
果
你
的
目
录
不
是
根
目
录
,
则
要
注
意
,
比
如
我
的
U
R
L
为
h
t
t
p
:
/
/
l
o
c
a
l
h
o
s
t
/
c
i
,
则
最
后
一
行
要
改
为
R
e
w
r
i
t
e
R
u
l
e
(
.
∗
)
1 [L] 如果你的目录不是根目录,则要注意,比如我的URL为http://localhost/ci,则最后一行要改为RewriteRule ^(.*)
1[L]如果你的目录不是根目录,则要注意,比如我的URL为http://localhost/ci,则最后一行要改为RewriteRule(.∗) /ci/index.php/$1 [L]
3.修改config.php
CI目录下的config文件夹,在config.php文件中,将$config[‘index_page’] = “index.php”; 修改为 $config[‘index_page’] = “”; 最后重启Apache 服务器,再次访问,就不需要输入index.php了。