Remove/Force www on Your Domain and 301 Redirect

December 18th, 2008 | Posted in Apache
0

You want to ensure that Google and other SEs only see one domain so you don’t penalized for duplicate content (www and non-www indexed pages are not the same and counted as duplicates).

.htaccess

To redirect to domain.com and 301 existing pages:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

To redirect to www.domain.com and 301 existing pages:

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

Google

If you a Google Webmaster account you can also make sure that the preferred domain matches your domain redirection choice.

  1. Log on to Google Webmaster Tools
  2. Click Settings
  3. In the Preferred Domain section make your selection and click Save

Related posts

Leave a Reply