1. 程式人生 > >如何在Apache開啟Rewrite環境

如何在Apache開啟Rewrite環境

ubuntu如何開啟Rewrite模組
在終端輸入:
sudo a2enmod rewrite 開啟Rewrite模組(停用模組,使用 a2dismod)
sudo gedit /etc/apache2/sites-available/default 修改下面的地方

<Directory />
Options FollowSymLinks
AllowOverride None(修改為AllowOverride All)
</Directory>
<Directory "/var/orioner">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
(修改為AllowOverride AllOrder allow,deny allow from all </Directory>

最後sudo /etc/init.d/apache2 restart。

在網站下面建立.htaccess檔案
修改.htaccess檔案屬性 chmod -R 777 .htaccess
Windows如何開啟Rewrite模組
環境:
系統 Windows
Apache 2.2
載入Rewrite模組:
在conf目錄下httpd.conf中找到
LoadModule rewrite_module modules/mod_rewrite.so
這句,去掉前邊的註釋符號“#”,或新增這句。
允許在任何目錄中使用“.htaccess”檔案,將“AllowOverride”改成“All”(預設為“None”):

AllowOverride controls what directives may be placed in .htaccess files.

It can be “All”, “None”, or any combination of the keywords:

Options FileInfo AuthConfig Limit

#
AllowOverride All
在Windows系統下不能直接建立“.htaccess”檔案,可以在命令列下使用“echo a> .htaccess”建立,然後使用記事本編輯。
CentOs開啟Apache的rewrite_module
centos的配置檔案放在: /etc/httpd/conf/httpd.conf
開啟檔案找到:
LoadModule rewrite_module modules/mod_rewrite.so
將前面”#”去掉,如果不存在則新增上句。
如果你的網站是根目錄的話:找到
程式碼如下

Options FollowSymLinks
AllowOverride None

將上面的None改為All
如果你的站點不在根目錄,設定如下:
程式碼如下