I’ve been looking for a good way to forward from my highpcs.com address to include the www for a while and finally took the time to set down and do it tonight. This little bit of code can be very helpful for canonization of a domain. All you have to do is put in your .htaccess file.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

While that seems simple it makes things easier for the search engine that crawls your site. For instance supercow.net is different to www.supercow.net to google. Duplicate sites and content make it difficult for google to properly rank and return results for your site. I’ve also used this to forward accounts on my server to their domain so there isn’t another “way” to access their site. For example:

domain.com/~user – in this case the domain is the server hosting the sites domain and the user is the public_html account that the files are stored in.

Using the .htaccess lines above you can forward the site right on to the proper domain without any problems. For more information or other ways of accomplishing the same task click here.