Making the www part optionalPosted by Roger Keays, 28 August 2007, 3:29 PM |
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]
| << Easy Page Actions with Facelets | Back to Blog | Javascript Fade Effects >> |