Redirecting to www.
Posted by Matt on March 8th, 2007
In Unix or Linux Apache with mod_rewrite this is easy.
Simply add the following to your .htaccess file in your public_html directory.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.domain.com/$1 [L,R]
If you have subdomains, this will redirect all of them to http://www.domain.com/, to prevent this do the following:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteCond %{HTTP_HOST} !^subdoamin1.domain.com [NC]
RewriteCond %{HTTP_HOST} !^subdomain2.domain.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R]