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).
Hi, the last line should
Hi, the last line should be:
RewriteRule ^(.*)$ http%{ENV:https}://www.example.com/$1 [r=301,L]see the addedd http in front of %{ENV:https}, this is needed because %{ENV:https} contains only the 's' character if %{HTTPS} on, not the whole scheme string.
Ah, and you may want to check the html formatting in the last code example.
Thanks,
Antonio
Your tips are well enough to
Your tips are well enough to know about search engine optimization for both new and old professionals. This information will be very helpful to me in the SEO.
Post new comment