当前位置: 移动技术网 > IT编程>开发语言>PHP > 解析如何去掉CodeIgniter URL中的index.php

解析如何去掉CodeIgniter URL中的index.php

2019年04月08日  | 移动技术网IT编程  | 我要评论

龙腾偏方,邪戏可人儿,三亚旅游景点大全

ci默认的rewrite url中是类似这样的,例如你的ci根目录是在/codeigniter/下,你的下面的二级url就类似这样http://localhost/codeigniter/index.php/welcome。不太好看,怎么把其中的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://www.nowamagic.net/codeigniter/,第三行需要改写为rewriterule ^(.*)$ /codeigniter/index.php/$1 [l]。
另外,我的index.php的同级目录下还有js文件夹和css文件夹,这些需要过滤除去,第二行需要改写为:rewritecond $1 !^(index\.php|images|js|css|robots\.txt)

3.将ci中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。
复制代码 代码如下:

/*
|--------------------------------------------------------------------------
| index file
|--------------------------------------------------------------------------

| typically this will be your index.php file, unless you've renamed it to
| something else. if you are using mod_rewrite to remove the page set this
| variable so that it is blank.

*/
$config['index_page'] = '';

重启apache

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网