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.
Asked
Active
Viewed 5.7k times
2 Answers
70
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)
Replace occurrences of "AllowOverride None" with "AllowOverride all" as necessary
sudo service apache2 restart ///restarts apache
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.

mikedugan
- 2,393
- 3
- 19
- 24
-
:Thank you so much, you sid in so easy languge withe description of each step. I've accepted and upvoted your answer. – PHPLover Jul 19 '13 at 12:20
-
1@mike - ya great answer, but cud you also mention what to do in production environment or give some links to look up for such cases – Stacy J Jan 28 '14 at 10:18
-
@StacyJ that would be a bit off topic for this question. Thoroughly read the /etc/apache2/apache2.conf or httpd.conf comments. Check http://httpd.apache.org/docs/current/misc/security_tips.html and https://help.ubuntu.com/12.04/serverguide/httpd.html for more info – mikedugan Jan 28 '14 at 11:17
-
What does "TL;DR version", mean? – Craig London Mar 19 '15 at 14:49
6
You didn't mention what commands did you try, so I will start with the basic one:
sudo a2enmod rewrite
You can also check if mod rewrite is already enable using:
apache2ctl -M

jmarceli
- 19,102
- 6
- 69
- 67