Redirecting WWW to non-WWW domains (or vice versa)

January 7, 2007 11:28pm
Categories: Organic SEO

How do we redirect domains with no WWW to domains with a WWW. This can be useful for "Link Equity Consolidation" in SEO.

So, first of all, why would anybody want to redirect a domain such as example.com to www.example.com? Well, many people feel that it allows for consolidation of in-link effects. And, technically, www is a subdomain of example.com. They are not the same, even if they may serve identical content. For example, if some people link to your site with example.com and others use www.example.com, then technically there are 2 different versions of your website. By performing a redirect, we tell search spiders that only one version of the domain should be used.

In performing this redirect, we prevent duplicate content from being a problem (www vs. non-www) and we also "combine" the power of the in-links, so we effectively have one domain at optimal performance instead of being split over two domains.

The way to accomplish this redirect is with mod_rewrite, an amazingly useful Apache Web-Server Module. The following pieces of code can be placed in the .htaccess file or the httpd.conf file. Personally, I use the httpd.conf because it doesn't have the performance hit of .htaccess, though that hit is so small that it's almost immeasurable. If you don't have a dedicated server then .htaccess is likely your only option.

To redirect Non-WWW to WWW:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^.*$ http://www.example.com%{REQUEST_URI} [R=301,L]

To redirect WWW to non-WWW:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]

Please note that the above codes with also translate the requested page. So the page that was being requested will be rewritten to its new form. http://example.com/page.html will get rewritten to http://www.example.com/page.html and vice-versa.

 
Submit RFP
TESTIMONIALS
“Darrin and I go back to 2000 when he had the Google Dance Tool and had started SEO Chat. Darrin's a great guy, is an SEO expert...”
Jim Boykin,
CEO,
We Build Pages
CONTACT
Telephone:
+1 (866) 695-3949