Forum Moderators: phranque
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
# Externally redirect all non-blank non-canonical hostname requests to the canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Externally redirect all subdomain requests having a spurious or extra
# "www" in the hostname back to the canonical subdomain hostname
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com [OR]
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.example\.com
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]