CI(4)隐藏URL里面的index.php过程总结

来源:互联网 发布:js舞蹈培训中心好不好 编辑:程序博客网 时间:2024/05/22 17:38
1、开启apache重定向功能:

(1)要修改Apache 的配置文件,让Apache支持rewrite_module,修改过程如下:打开apache的配置文,conf/httpd.conf :LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉;

(2)搜索 AllowOverride None 即 Options Indexes FollowSymLinks MultiViews下面那个,修改为 AllowOverride All (一般情况下是有两个,两个都要修改!)。


2、项目的根目录(与index.php文件是同一级目录)下新建一个.htaccess文件,并写入如下内容:

RewriteEngine on
RewriteBase /ci/project  //注意这里面的/ci/project/表示的是项目名称的(apache配置项目时的目录名称)
RewriteCond $1 !^(index\.php|images|robots\.txt) //对于样式、JS、静态元素是不能rewrite的所以加这一句
RewriteRule ^(.*)$ index.php/$1 [L]

或:
RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/project/index.php/$1 [L]

3、修改CI框架下的‘/application/config/config.php’配置文件:

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



实例:

    初始访问“helloworld”页面链接:localhost/ci/project/index.php/helloworld

    修改后访问链接:localhost/ci/project/helloworld
0 0
原创粉丝点击