mod_rewrite

Quick guide to URL rewriting with Apache

Redirecting whole websites or single webpages with mod_rewrite is a very important feature when doing search engine optimization (SEO) or when moving from one webserver or domain to another.

Redirection is usually done with a small block of code that is added to an .htaccess file in your websites root path. The code snippet looks like:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\.example\.com$ 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

It is often misunderstood and the bulletin boards have hundrets of incomplete or wrong assumptions about Apache and mod_rewrite. That's why I decided to write an article about it.