Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this in my /srv/www/htdocs/.htaccess file:

RewriteEngine On #turn on rewite engine
RewriteRule ^schedule/?$ index.php?page=schedule [NC,L]
RewriteRule ^music/?$ index.php?page=music [NC,L]
RewriteRule ^thefamily/?$ index.php?page=thefamily [NC,L]
RewriteRule ^contact/?$ index.php?page=contact [NC,L]

I go to http://localhost/contact and I get 404 error. On my remote server however, this code in .htaccess works fine. How do I get RewriteRule to work on Apache2? I googled, and read that this command would make it work: # a2enmod rewrite but it did not [I did restart apache2 too].

I even added RewriteEngine On to my /etc/apache2/sites-available/default file [Inside the VirtualHost] but that didn't fix it either.

I'm running it from Ubuntu 11.04. Any help appreciated, thanks!

share|improve this question
up vote 2 down vote accepted

The default configured apache virtualhost on debian (and I'm assuming Ubuntu) does not read .htaccess files. To Turn it on, open up the default config file (/etc/apache2/sites-available/default), look for something similar to:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all

Change the line "AllowOverride None" to "AllowOverride All". Reload or restart apache (/etc/init.d/apache reload). AllowOverride restricts the directives that can be placed in an .htaccess file, when it is set to None, apache never parses the file.

share|improve this answer
I had tried this in the /var/www/ <Directory> entry before I saw your post, but it didn't work. However I changed the root ["<Directory />"] directory's ALlowOverride to "All" and it works! Thanks – Matt May 3 '11 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .