To enable mod_rewrite on Ubuntu is pretty easy what we have to do is, first we enable the apache module for mod rewrite with this line.
-
-
sudo a2enmod rewrite
-
After that we have to edit the file /etc/apache2/sites-avalible/default, then we look for this:
-
-
<Directory /var/www/>
-
Options Indexes FollowSymLinks MultiViews
-
AllowOverride None
-
Order allow,deny
-
allow from all
-
# This directive allows us to have apache2’s default start page
-
# in /apache2-default/, but still have / go to the right place
-
#RedirectMatch ^/$ /apache2-default/
-
</Directory>
-
And then we replace “AllowOverride None” by “AllowOverride All”, this line tells apache to read the .htaccess file, that is the file where we will put our rewrite rules.
I have also taked out the MultiViews option since it was messing with my rewrite rules
-
-
<Directory /var/www/>
-
Options Indexes FollowSymLinks
-
AllowOverride All
-
Order allow,deny
-
allow from all
-
# This directive allows us to have apache2’s default start page
-
# in /apache2-default/, but still have / go to the right place
-
#RedirectMatch ^/$ /apache2-default/
-
</Directory>
-
finally we just reload apache
-
-
sudo /etc/init.d/apache2 restart
-
now we have pretty urls for our sites. :)
thanks a lot for such a wonderful tutorial.
Verify that all rules have been applied. ,
This piece is the best i have seen on enabling mod_rewrite. Thanks man.
THANKS A LOT!!
Most sites talk you through enabling mod_rewrite and loading it on non-Ubuntu Linux based systems…I really don’t understand why, I believe Ubuntu is a ver well known, widely distributed Linux distro…maybe it’s because most ubuntu users are noobs, lol…anyways…this is just what I was looking for… thank you…=]