CodeIgniter 去掉index.php

首先需要配置下 Apache的mod_rewrite:

1. 在[Apache安装目录]/conf/httpd.conf中:

     找到#LoadModule rewrite_module modules/mod_rewrite.so,去掉前面的注释符号#。

     如果没有这行,请添加。并确认apache安装目录下的modules文件夹中是否有mod_rewrite.so这个文件。

     这样就启用了Mod Rewrite功能。


2. 在[Apache安装目录]/conf/httpd.conf中找到

[python]  view plain copy
  1. <Directory />  
  2.     Options FollowSymLinks  
  3.     AllowOverride None  
  4.     Order deny,allow  
  5.     Deny from all  
  6. </Directory>  


把“AllowOverride None”改成“AllowOverride All”,这样所有的文件夹都支持.htaccess了,或者针对指定的文件夹启用.htaccess,

可以在[Apache安装目录]/conf/httpd.conf中加入


[ruby]  view plain copy
  1. <Directory "D:/Program Files/xampp/htdocs/mss">  
  2.     Options Indexes FollowSymLinks  
  3.     AllowOverride All  
  4.     Order allow,deny  
  5.     Allow from all  
  6. </Directory>  


这种做法一般是和虚拟主机配置在一起的.


3. 我使用的是虚拟主机,所以第二步中的配置,我是在[Apache安装目录]/conf/extra/httpd-vhost.conf 中进行修改


[ruby]  view plain copy
  1. <VirtualHost *:80>  
  2.     ProxyPreserveHost On  
  3.     DocumentRoot "D:/Program Files/xampp/htdocs/mss"  
  4.     ServerName  xxx.music.baidu.com  
  5.     DirectoryIndex index.php  
  6.     <Directory "D:/Program Files/xampp/htdocs/mss">   
  7.         Options Indexes FollowSymLinks   
  8.         AllowOverride All   
  9.         Order allow,deny   
  10.         Allow from all   
  11.     </Directory>  
  12. </VirtualHost>  


重启Apache,mod_rewrite 生效!


4. 剩下是codeigniter的修改,it's very important!!!

将 .htaccess 修改为

[php]  view plain copy
  1. RewriteEngine on     
  2. RewriteCond $1 !^(index\.php|images|robots\.txt)     
  3. RewriteRule ^(.*)$ /index.php/$1 [L]  

然后移至网站根目录!(切记,否则还是访问还是无效的。)


其它操作系统下Apache rewrite配置可以参见: http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值