TIP: Force "www" in URL with .htaccess 2
This neat little trick will force all browsers that are trying to access your website from domain.com into a standardized gateway of www.domain.com for increased search engine consistency, as well as a consistent aesthetic appearance to regular users.
Add the following snippet of code to the .htaccess of your public html directory where you would like to use this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.your-website\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Updated .htaccess to allow subdomains at the suggestion of Jim, The Blogaholic. If you don’t want this functionality, just remove the third line!
Voila, 301 forwarded to the same homepage every time!
(BTW, this also prevents having such a varying pagerank between domain.com and www.domain.com some of the time.)

Don't forget to exclude sub-domains when re-directing to www (otherwise you won't be able to have sub-domains for your website!)
http://www.theblogaholic.com/2011/01/16/force-www…
Great suggestion! Updated my original post, thanks!