Mod Rewrite Rules You Can Live With

I had some issues upgrading to the latest apache 2.0, which turned out to have apparently broken my mod rewrite rules.

As usual, my problem turned out to be a trivial fix. In httpd.conf I hadn’t merged the AllowOverride None line directly…to use mod rewrite rules in your .htaccess file correctly, this value has to be set to “All” instead of “None”.

AllowOverride All will allow you to use mod rewrite rules in your .htaccess file.

Here’s a simple test:

Open foo.html and bar.html, and add those respective words to the file. (foo.html contains “foo”, bar.html contains “bar”).

Now, open up your .htaccess file (typically, /path/to/yoursite.com/htdocs/.htaccess), and add the following mod rewrite rules:

RewriteEngine on
RewriteRule  foo.html    bar.html  [L]

Now access: yoursite.com/foo.html

You should see the word “bar” instead of “foo” in your browser.

For debugging, try enabling mod rewrite’s log level to 9.

See the mod rewrite documentation for more info and examples of mod rewrite rules.