I think, therefore I blog

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 http://harveynorman.com.au) 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. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

Please visit https://RogerKeays.com/blog/making-the-www-part-optional to add your comments.

Join 3,559 People Who Think Outside The Box

I write every Sunday about travel, psychology, technology, and all sorts of interesting stuff. It's completely free, and you can leave whenever you like. Subscribe now, and you'll be the first to get new articles each week.

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?