Apache mod_rewrite doesn’t seem to work in Windows

I had this strange phenomenon that mod_rewrite instructions in the .htaccess file worked online on my ISPs server, but not on my local Windows machine that also has an Apache server running on it.

I kept getting 404 errors: page not found.

Which is a bit annoying: I’ve got drupal, joomla and other software running on my local server, but none of them could use ‘clean URLs,’ which is what I want to use.

It turns out that the default configuration of Apache on windows is to NOT allow .htaccess to be used.

So the problem wasn’t that the mod_rewrite didn’t work. The real problem was that the .htaccess file was just ignored.

The best solution for that is to modify your httpd.conf file. (Stop the Apache service before you modify it. Start it again when completed).

If you’ve installed, e.g, drupal in a directory “c:\websites\drupal” and you want to use mod_rewrite for clean URLs, then you’d have to add the following lines to the httpd.conf file:

<Directory “C:/websites/drupal/”>
AllowOverride All
Order allow,deny
Allow from all

You have to do this for each directory / folder you want to use .htaccess in.

The – far less secure- alternative is to change the default settings of your Apache and by default allow .htaccess to be used.