Configure ubuntu to use mod_rewrite

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.

  1.  
  2. sudo a2enmod rewrite
  3.  

After that we have to edit the file /etc/apache2/sites-avalible/default, then we look for this:

  1.  
  2. <Directory /var/www/>
  3.     Options Indexes FollowSymLinks MultiViews
  4.     AllowOverride None
  5.     Order allow,deny
  6.     allow from all
  7.     # This directive allows us to have apache2’s default start page
  8.     # in /apache2-default/, but still have / go to the right place
  9.     #RedirectMatch ^/$ /apache2-default/
  10. </Directory>
  11.  

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

  1.  
  2. <Directory /var/www/>
  3.     Options Indexes FollowSymLinks
  4.     AllowOverride All
  5.     Order allow,deny
  6.     allow from all
  7.     # This directive allows us to have apache2’s default start page
  8.     # in /apache2-default/, but still have / go to the right place
  9.     #RedirectMatch ^/$ /apache2-default/
  10. </Directory>
  11.  

finally we just reload apache

  1.  
  2. sudo /etc/init.d/apache2 restart
  3.  

now we have pretty urls for our sites. :)

4 thoughts on “Configure ubuntu to use mod_rewrite

  1. ARCRA

    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…=]

Leave a Reply

Your email address will not be published. Required fields are marked *