自己记录一下 去掉index.php
首先要保证:$autoload['helper'] = array('url');
配置如下
A. .htaccess文件必须放在CI的根目录下和index.php文件在同一目录。
.htaccess 文件的内容如下:
RewriteEngine on
RewriteCond $1 !^(index\\.php|images|robots\\.txt)
RewriteRule ^(.*)$ /CI/index.php/$1
//CI为目录,如果ci直接放在根目录。路径就是/index.php/$1
B.在apache配置上,注意httpd.conf文件里:
1、//开启rewrite
LoadModule rewrite_module modules/mod_rewrite.so
2、//开启 .htaccess
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
注意,配置好后要重启apache。
另外,注意几个文件:
application\\config\\routes.php---这个文件设置初始加载的默认控制器文件(controller)
application\\config\\config.php---这个文件设置初始配置,但是,自打我去掉index.php后,$config['index_page'] = 'index.php';--这个貌似不再起作用了。为空也木事。。。
http://codeigniter.org.cn/user_guide/general/urls.html http://www.crazyfriday.net/2013/02/%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4url%E4%B8%ADindex-php%E7%9A%84%E7%BB%88%E6%9E%81%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/ 如何删除URL中index.php的终极解决方案 按照这个方法,也不行呢 蒲哥 发表于 2013-8-30 15:21 static/image/common/back.gif
按照这个方法,也不行呢
如果你的项目是通过虚拟主机配置的:
1)确认apache httpd.conf中已经开启rewrite模块(无#代表已开启)
LoadModule rewrite_module libexec/mod_rewrite.so
2)确认apache httpd-vhost.conf中DocumentRoot有访问权限,假设我的根目录是:"D:/xampp/htdocs/CodeIgniter"
DocumentRoot "D:/xampp/htdocs/CodeIgniter"
ServerName http://codeigniter.test.com-->url中要访问的域名
<Directory "D:/xampp/htdocs/CodeIgniter">
Options +Indexes +FollowSymLinks
AllowOverride All -->不能是None,否则会报404
Order allow,deny
Allow from All -->不能是Deny from all,否则会报无权访问
</Directory>
3)在如上根目录下建立.htacess文件,加入如下配置:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1
</IfModule>
4)重启apache ,开始测试吧。如:http://codeigniter.test.com/News/index
5)说明:第2中的修改与httpd.conf文件无关,httpd.conf无须做任何更改。
无需修改config.php中$config['index_page'] = 'index.php';
此做法如果输入http://codeigniter.test.com/index.php/News/index也能访问,不过已经能实现去除index.php了。
在本地,不是在虚拟机
页:
[1]