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

I guess I'd call myself a problem solver. Either that, or I'm some sort of organic machine designed to convert oxygen into carbon dioxide. You could go either way on that. I'm into languages and stuff. I wrote a book. It's okay, I guess. What else? I like reading, swimming, eating, and playing music. Satisfied? Sheesh.

Leave a Comment

Please visit to add your comments.