首页 > 代码库 > PHP CI(CodeIgniter) 如何去掉url中的index.php

PHP CI(CodeIgniter) 如何去掉url中的index.php

1、打开Apache配置文件httpd.conf,找到

1 #LoadModule rewrite_module modules/mod_rewrite.so

去掉前面的#

 

搜索AllowOverride,将相应Directory下的AllowOverride设置为All

1 AllowOverride All

 

2、在CI的根目录下,建立.htaccess文件,文件内容如下

 1 RewriteEngine On   2  3 RewriteCond %{REQUEST_URI} ^system.*   4 RewriteRule ^(.*)$ /index.php?/$1 [L]  5  6 RewriteCond %{REQUEST_URI} ^application.*   7 RewriteRule ^(.*)$ /index.php?/$1 [L]   8  9 RewriteCond %{REQUEST_FILENAME} !-f  10 RewriteCond %{REQUEST_FILENAME} !-d  11 RewriteRule ^(.*)$ index.php?/$1 [L]

 

3、打开文件application/config/config.php,$config[‘index_page‘] = "index.php";改为$config[‘index_page‘] = "";

1 $config[index_page] = ""; 

 

4、重启Apache