Force URL to use www
Thursday, January 28th, 2010
Here is a quick and easy solution to those who want to force all URLs to lead with www. For example, rewrite http://yourdomain.com as http://www.yourdomain.com. There are those that argue that is it is more SEO optimized to do this. To do this, add the following to your top (root) .htaccess file (or create one if it does not exist already):
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
$1: RewriteRule backreference – requested directory/file passed to rewritten URL
R=301: Permanent Redirect – 301 redirect is the most efficient and SEO Friendly method for redirection.
L: Stop the rewriting process here and don’t apply any more rewriting rules.


