天天看點

codeigniter 去掉index.php,CodeIgniter 去掉index.php

由于使用的是windows開發環境,伺服器用的是xampp,今天在做codeigniter 去掉index.php 的時候,需要用到apache的mod_rewrite.

首先需要配置下 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中找到

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

把“AllowOverride None”改成“AllowOverride All”,這樣所有的檔案夾都支援.htaccess了,或者針對指定的檔案夾啟用.htaccess,

可以在[Apache安裝目錄]/conf/httpd.conf中加入

Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny

Allow from all

這種做法一般是和虛拟主機配置在一起的.

3. 我使用的是虛拟主機,是以第二步中的配置,我是在[Apache安裝目錄]/conf/extra/httpd-vhost.conf 中進行修改

ProxyPreserveHost On

DocumentRoot "D:/Program Files/xampp/htdocs/mss"

ServerName xxx.music.baidu.com

DirectoryIndex index.php

Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny

Allow from all

重新開機Apache,mod_rewrite 生效!

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

将 .htaccess 修改為

RewriteEngine on

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

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

然後移至網站根目錄!(切記,否則還是通路還是無效的。)

其它作業系統下Apache rewrite配置可以參見: http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x/