Making The www Part Optional

By , 28 August 2007

Making The www Part Optional

I always get a surprise when I try to visit a well known company's website (e.g and get a 404 error. The problem here is that I get lazy and often don't bother putting in the www part of the hostname. I guess the sysadmins must be even lazier than me, because adding a mod_rewrite rule to allow this shortcut is very easy. Here's what it looks like:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^domain2\.net$ [OR]
RewriteCond %{HTTP_HOST} ^domain3\.com$ 
RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=permanent]
Making The www Part Optional

About Roger Keays

Making The www Part Optional

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Leave a Comment

Please visit to add your comments.