環境
====
Ubuntu
Apache (sudo apt-get install apache2)
STEP 1: 啟用rewrite子產品
===================
采用二進制檔案安裝的apache(apt-get install),預設會啟用一部分子產品。在apache2的配置目錄下,有兩個目錄
/etc/apache2/mods-enabled/ #已經被啟用的子產品
/etc/apache2/mods-available/ #目前系統中可用的子產品
可用使用指令來啟用或禁用子產品:
a2enmod 子產品名
a2dismod 子產品名
執行指令其實是在/etc/apache2/mods-enabled/目錄下建立或删除一個子產品的連結檔案。是以也可以手動進行,
cd /etc/apache2/mod-enabled
sudo ln -s ../mods-available/rewrite.load rewrite.load
STEP 2:修改配置檔案
=================
sudo vim /etc/apache2/sites-enabled/000-default
替換
AllowOverride None
為
AllowOverride All
Note: /etc/apache2/sites-enabled/000-default實際上是/etc/apache2/sites-available/default的連結。
STEP 3:添加Rewrite規則
===================
在需要隐藏index.php的目錄下建立.htaccess檔案,内容如下:
<IfModule mod_rewrite.c> RewriteEngine on #不顯示index.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule> |
REFERENCE
=========
1.http://hi.baidu.com/liheng_2009/item/7676267547a49322d6a89cdf
2.http://www.5idev.com/p-thinkphp_htaccess_rewrite.shtml