Forum Moderators: phranque
RewriteCond %{http_host} !^www.example.com$ [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc,L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Externally redirect non-canonical non-blank hostname requests to canonical "www" hostnames
RewriteCond %{HTTP_HOST} !^www\.[a-z0-9][a-z0-9\-]+[a-z]\.([a-z]{3,6}|(co\.)?[a-z]{2})$ [NC]
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*([a-z0-9][a-z0-9\-]*[a-z]\.([a-z]{3,6}|(co\.)?[a-z]{2}))\.?(:[0-9]+)?$ [NC]
RewriteRule ^(.*)$ http://www.%2/$1 [R=301,L]