問題描述
我在我的機器上使用 Ubuntu 12.04 LTS linux.我已經在上面安裝了 LAMP.現在我想啟用 mod_rewrite 模塊.我做了很多谷歌并嘗試了很多技巧,但無法啟用 mod_rewrite.誰能幫我啟用 mod_rewrite?提前致謝.
I'm using Ubuntu 12.04 LTS linux on my machine. I've already installed LAMP on it. Now I want to enable the mod_rewrite module. I did google a lot and tried lots of tricks but couldn't be able to enable mod_rewrite. Can anyone help me to enable the mod_rewrite? Thanks in advance.
推薦答案
TL;DR version -- 在你的終端中執行以下操作:
TL;DR version -- do the following in your terminal:
sudo a2enmod rewrite && sudo service apache2 restart
有解釋——在你的終端中執行以下操作:
With explanations -- do the following in your terminal:
ls -l /etc/apache2/mods-available/rewrite.load ///if it prints out rewrite.load, it's there and ready to go
sudo a2enmod rewrite //enables the mod
ls -l /etc/apache2/mods-enabled/rewrite.load // shows created symlink
sudo vi /etc/apache2/sites-available/default //opens the file in vi (you can also use vim or nano)
根據需要將出現的AllowOverride None"替換為AllowOverride all"
Replace occurrences of "AllowOverride None" with "AllowOverride all" as necessary
sudo service apache2 restart ///restarts apache
在/etc/apache2/sites-available 中編輯您的虛擬主機條目并將 AllowOverride All
添加到 DocumentRoot.您的虛擬主機最終應如下所示:
Edit your virtual host entry in /etc/apache2/sites-available and add AllowOverride All
to the DocumentRoot. Your virtual host should ultimately look something like this:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/vhosts/example.com
<Directory /var/www/vhosts/example.com>
AllowOverride all
</Directory>
</VirtualHost>
雖然這不適合生產環境,但它適用于本地開發.
Although this isn't suitable for production environments, it works just fine for local development.
這篇關于如何在 ubuntu 上的 LAMP 中啟用 mod_rewrite?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!