去掉CodeIgniter(CI)默认url中的index.php

去掉CodeIgniter(CI)默认url中的index.php

//1.打开apache的配置文件,conf/httpd.conf :LoadModule rewrite_module modules/mod_rewrite.so

//把该行前的#去掉。

//搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为:AllowOverride All

//2.在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

//如果文件不是在www的根目录下,

例如我的是://http://localhost/test/ci_demo_1/index.php///第三行需要改写为

RewriteRule ^(.*)$ /test/ci_demo_1/index.php/$1 [L]

//另外,我的index.php的同级目录下还有assets文件夹,这些需要过滤除去,第二行需要改写为:

RewriteCond $1 !^(index\.php|images|assets|robots\.txt

//3.将CI中配置文件(application/config/config.php)中

$config['index_page'] = "index.php";

改成$config['index_page'] = "";

重启apache,完成。

参考:https://blog.csdn.net/qq3559727/article/details/52370771

猜你喜欢

转载自blog.csdn.net/awake720/article/details/80938767
今日推荐