2013-07-19 22 views
15

我在我的機器上使用Ubuntu 12.04 LTS linux。我已經安裝了LAMP。現在我想啓用mod_rewrite模塊。我做了很多谷歌,並嘗試了很多技巧,但無法啓用mod_rewrite。任何人都可以幫我啓用mod_rewrite嗎?提前致謝。如何在ubuntu上啓用LAMP中的mod_rewrite?

回答

66

TL; DR版本 - 在您的終端中執行以下操作:

sudo a2enmod rewrite && sudo service apache2 restart 

解釋 - 終端:

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無」用「的AllowOverride所有」的出現是必要

sudo service apache2 restart ///restarts apache 

編輯在/ etc/apache2的/網站,提供虛擬主機條目,並添加AllowOverride All到DocumentRoot的。您的虛擬主機最終應該是這個樣子:

<VirtualHost *:80> 
    ServerName example.com 
    DocumentRoot /var/www/vhosts/example.com 
    <Directory /var/www/vhosts/example.com> 
    AllowOverride all 
    </Directory> 
</VirtualHost> 

雖然這是不適合於生產環境,它工作得很好,爲當地的發展。

+0

:非常感謝你,你用這麼簡單的語言來描述每一步。我已經接受並且贊成你的回答。 – PHPLover

+1

@mike - ya很好的答案,但是你也可以提一下在生產環境中應該做些什麼,或者提供一些鏈接來查找這種情況。 –

+0

@StacyJ對於這個問題有點偏離主題。徹底閱讀/etc/apache2/apache2.conf或httpd.conf註釋。請查閱http://httpd.apache.org/docs/current/misc/security_tips.html和https://help.ubuntu.com/12.04/serverguide/httpd.html瞭解更多信息 – mikedugan

5

你沒有提到你嘗試了哪些命令,所以我會用一個基本的開始:

sudo a2enmod rewrite 

您還可以檢查是否國防部重寫已經能夠使用:

apache2ctl -M 
相關問題