apache開啟rewrite重寫


命令開啟

sudo a2enmod rewrite

sudo /etc/init.d/apache2 restart

即可開啟重寫,不行的話再試下下面方法

 

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 All)

Order 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

將前面"#"去掉,如果不存在則添加上句。

如果你的網站是根目錄的話:找到

 代碼如下 復制代碼

<Directory />
  Options FollowSymLinks
  AllowOverride None 
</Directory>

將上面的None改為All

如果你的站點不在根目錄,設置如下:

 代碼如下 復制代碼

<Directory "/var/www/html/my_directory"> 

Order allow,deny
Allow from all
AllowOverride All
</Directory>

OK,然后重啟服務器,service httpd restart ,這樣.htaccess就可以使用了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM