DiggDigg It! Slashdot It!Slashdot It! DeliciousDelicious It!

Enable Apache Mod_Rewrite and .htaccess files on Ubuntu

I run Ubuntu 9.10 (Karmic Koala) on my Lenovo Thinkpad T60.  I have apache2 and PHP5 installed for web development.  By default Mod_Rewrite would not work.  If found it was because my htaccess file was not being read.  This is because AllowOverride is set to None in the default apache config file.  You need to get your .htaccess files working so you can use mod_rewrite.  Here's how to do it:

1. First Make sure mod_rewrite is Enabled/Loaded:

  sudo a2enmod rewrite

2. Edit the  "sites-available" config file (Update AllowOverride None to AllowOverride All):

  sudo gedit /etc/apache2/sites-available

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>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

3. Restart the Apache2 HTTP Server

  sudo /etc/init.d/apache2 restart

Note:  In the old Apache 1.3 days this would have been done in the apache.conf or httpd.conf file

DiggDigg It! Slashdot It!Slashdot It! DeliciousDelicious It!


Sections