您的位置:首页 > 编程语言 > PHP开发

去掉php框架CI默认url中的index.php

2015-03-12 10:49 666 查看
CI默认的rewrite url中是类似这样的

例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样 http://localhost/CodeIgniter/index.php/welcome。
不太好看,怎么把其中的index.php取掉呢?

解决方法如下:

第一步:

Apache Url Rewrite 配置(php伪静态)

检查 Apache 中 conf/httpd.conf 中是否存在如下一段代码:

#LoadModule rewrite_module modules/mod_rewrite.so

把 LoadModule前边的#去掉。

第二步:

在网站根目录添加.htaccess(和application、system在一个目录下)

内容为:

RewriteEngine on

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

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


备注:

1、要注意 /index.php/$1 要根据你目录(Web 目录,比如 http://www.domain.com/index.php)的实际情况来定。
比如网站根目录是 /ci/index.php 则要写成 /ci/index.php/$1

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

上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除)

第三步:

修改application/config.php

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

修改为:$config['index_page'] = "";

第四步:

httpd.conf文件中:

AllowOverride None

改为

AllowOverride All

注意:如果你做了虚拟站点,在httpd-vhosts.conf中做了多站点配置,就像我这样:

<VirtualHost *:81>
DocumentRoot "d:/wamp/www/nxtv"
ServerName 81
<Directory "d:/wamp/www/nxtv">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:82>
DocumentRoot "d:/wamp/www/codeigniter220"
ServerName localhost:82
<Directory "d:/wamp/www/codeigniter220">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>


要记得 把 AllowOverride None 改为 AllowOverride All,我就在这里吃亏了=。=
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: