If you’re trying to enable mod_rewrite for apache2 on your ubuntu server (or any other distrib) and nothing works, this little writeup might save you a few hours of frustration !
To enable mod_rewrite on ubuntu server you should write the following command:
sudo a2enmod rewrite
Apparently, this isn’t enough to do the job, it actually enables the module and loads it, but it won’t show up in
sudo apache2ctl -l
after you’ve enabled mod_rewrite, it’s time for the fix to make it actually work !
head to /etc/apache2/sites-enabled/
and then edit the site you’re currently using mostly it’ll be the file: 000-default
When you open the file, you’ll notice it’ll probably look like this :
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride none
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride none
Order allow,deny
allow from all
</Directory>
You need to replace the occurrence of AllowOverride none to AllowOverride all
now the file should look like this :
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
After editing your file, you will need to restart your apache2 server to see the changes !
in your terminal, type:
sudo service apache2 restart
Now fire up your browser and check your working mod_rewrite !, happy development.
Thanks !
Thanks 🙂
very useful
thanks a lot 🙂