WWW Redirect [htaccess]

Force all non-www. links to www. “subdomain”. Because technically “www.WHATEVER.com” is a subdomain of “WHATEVER.com”, just the same as it would be for “mysite.WHATEVER.com”.

#Options +FollowSymLinks
RewriteEngine on

#force all links with yourdomain ---------------------
RewriteCond %{HTTP_HOST} ^YOURDOMAIN.com [NC]

#force anything that DOESN'T have www to yourdomain ---------------
#RewriteCond %{HTTP_HOST} !^www.YOURDOMAIN.com [NC]

RewriteRule ^(.*)$ http://www.YOURDOMAIN.com/$1 [L,R=301]

Also from Helicon – uses placeholders

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

Leave a Reply

Your email address will not be published. Required fields are marked *