CodeIgniter如何去掉Index.php-apache服务器
CI默认的rewrite url中是必须加上一个index.php,这样看起来URL不是很美观,下面我就给大家分享一下如何去掉CodeIgniter中的index.php
-
打开你的WEB服务器的httpd.conf文件,以本地的XAMPP环境为例,点击面板上的“config”,然后选择“Apache(httpd.conf)”
-
找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉。保存该文件
-
进入到CI根目录,新建.htaccess文件,输入
RewriteEngine on
RewriteCond $1 !^(index\.php|style|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
当然如果你的目录不是根目录,则要注意,比如我的URL为http://localhost/ci,则最后一行要改为RewriteRule ^(.*)$ /ci/index.php/$1 [L]
-
保存.htaccess可以使用另存为的方式,然后文件类型选择“All Files”即可保存
-
最后到CI目录下的config文件夹下,在config.php文件中,将$config['index_page'] = "index.php"; 修改为 $config['index_page'] = ""; 最后重启Apache 服务器,再次访问,就不需要输入index.php了。
来源:百度经验 https://jingyan.baidu.com/album/2fb0ba4054cd5900f3ec5f52.html?picindex=1