Improve Your SEO By Redirecting Non-WWW Traffic to WWW

Setup the WWW Subdomain

If you haven't already, make sure you allow visitors to access your site through your root domain as well as the www subdomain (e.g., http://example.com and http://www.example.com). Even though the www subdomain isn't required, some still type it in out of habit. You can do this either by adding a CNAME record with your domain's registrar or by adding a ServerAlias directive in your Apache virual host httpd.conf.

Congratulations! You've successfully decreased your site's SEO performance / PageRank.

Now sites like Google think that you are operating two sites with the same information! If you want to confirm this, try entering the following into Google's search box:

site:http://yoursite.com

If you see that the pages it returns are both www and non-www, you have what is called a canonical url issue where the search engine doesn't know which is the "best" URL to use.

Setup the Redirect

To fix the canonical issue, force your Web server to redirect all traffic to either domain. For example, if you are using Linux with Apache, add the following to your .htaccess file (already included in Drupal .htaccess files):

# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,L]

UPDATE: If you also have SSL turned on and want to redirect HTTPS traffic as well, use this:

# Determine if HTTPS
RewriteCond %{HTTPS} on
RewriteRule .* - [ENV=https:s]

# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ %{ENV:https}://www.example.com/$1 [r=301,L]

This permanently redirects all traffic to example.com to www.example.com, thus establishing your canonical URL as www.example.com and avoiding any negative SEO effects. This example may also be found in the default .htaccess file that comes with Apache (you may need to uncomment it).

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.

More information about formatting options