example.com vs. www.example.com… trouble!

By | | Search Engine Marketing

If you had the SitePoint SEM Kit you’d already know about this, but since some folks haven’t actually bought it yet, here’s something important you should know.

Most web servers (therefore most web sites) are configured to show the same content whether visitors request a page with or without the www in the address. So h t t p : / /example.com is likely to give you the same content as h t t p : / / www.example.com.

If your website does this, that’s not good, because you are showing the same content to the search engines under more than one URL. In other words, your site is serving up duplicate content.

Now, some folks hear “duplicate content” and assume that there’s some kind of penalty involved, but that’s not really the problem. The problem is that search engines have to choose *one* of those copies, and declare it to be the official “canonical” URL. If you’ve put all of your effort into promoting www.example.com, you’d hope that the search engines would see that as the canonical version… but will they?

Maybe, but if God doesn’t play dice with the Universe, you definitely shouldn’t play dice with the search engines. Especially when a post at Threadwatch, the official blog of search engine spammers*, is talking about how to take advantage of your little mistake to sabotage your rankings.

The right solution is to pick one version (I like the www. version myself) and redirect the other version to it, with a 301 Permanent redirect. There are many ways to accomplish this, on most Apache setups it’s as simple as using your .htaccess file.

Example 1, .htacces entry to redirect anything.example.com (and example.com itself) to www.example.com:

Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.example\.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Example 2, to redirect anything.example.com (except for subdomain1.example.com and subdomain2.example.com) to www.example.com:

Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} !^www|subdomain1|subdomain2\.example\.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

This code is provided for entertainment purposes only, use at your own risk, yadda yadda.

*Hi, Nick, just trying to boost your rankings for a targeted search term.

Written By:

Dan Thies

Dan has been helping his clients (and friends) promote their Websites, though his company SEO Research Labs, since 1996. Dan is the author of SitePoint's The Search Engine Marketing Kit and also maintains Key Words: SitePoint's Search Engine Marketing blog.

Website
>> More Posts By Dan Thies

 

{ 40 comments }

The YPI March 31, 2009 at 8:51 pm

This redirection is of great use, but the problem is that some sites dont allow user to manipulate .htaccess file.
In such scenario we need to do redirection at php level itself, using server variable, and header function.
Hope you find it useful.
Thanks,

www.beautywalk.com/ January 23, 2009 at 2:57 am

ghulab September 26, 2008 at 2:41 pm

i want to in my yahoo acount

ghulab September 26, 2008 at 2:36 pm

sadfsdgfdga

adrian felipen acosta August 11, 2008 at 3:42 am

hello what estan bien yo mal adios

cristobal June 3, 2008 at 12:32 am

tengo más de 17 días que no he podido abrir la bandeja de entrada para leer los correos. Tengo más de 14 años de tener este correo es decir he posesionado profesionalmente mi correo, con más de 5.000 targetas de presentación, mis escritos e infinidades de comunicacion nacional e internacionalmente. por favor ayudenme a recuperar mi correo. Es una necesidad

Anonymous March 22, 2008 at 2:57 am

SDFGHJKLŞ

Anonymous February 20, 2008 at 4:21 pm

我是你哥

Irish Jim February 6, 2008 at 1:07 pm

WWW is NOT DEPRECATED because some high schoolers decided to create a webpage against it. Since some sites require WWW for technical reasons, deprecating www for sites that don’t require it create inconsistencies.

ayşe August 11, 2007 at 3:49 am

sen elif ablanın düyününde nasıl giyinecen aşkım

Anonymous May 26, 2007 at 1:03 am

sqxdcxq

RonnyStalker March 27, 2007 at 3:03 am

Just a note for those who use e-commerce on thier site. I decided to alter my .htaccess to rewrite “www”‘s to “non-www”‘s. Trouble was, i forgot that my credit card merchant services provider was set up to refuse any POSTs unless they were from a very specific URL (www sensitive) for security. I just reversed the rewrite rule to fix the problem.

Anonymous March 9, 2007 at 7:24 pm

!l$
jk,k

k 12

mùmùùmù

SaN-DeeP December 1, 2006 at 8:57 pm

If a domain is indexed for a long time (2 years) with example.com and now decided to turn on to http://www.example.com yahoo still adds a 301 redirect penalty ? (problem faced by yahoo in late 2004)

Is there a fix to this yet.

Gary LaPointe November 19, 2006 at 9:31 am

I always design my sites to pick one or the other. If it’s not possible one goes to a page that says “use the other address”. It’s just always seemed better to me…

It makes me cRaZy that some sites still don’t support the URL without the WWW. And sometimes if they’ve chosen not to promote the WWW, using it gives an error! Talk about shooting yourself in the foot!

Gary
http://GarySaid.com/

pepa November 17, 2006 at 1:19 am

if i yous some web site its not work

dealwave June 8, 2006 at 3:40 pm

How come sitepoint is using 302 redirects instead of the 301. Browsing to this page without the www (http://sitepoint.com/blogs/2005/06/14/examplecom-vs-wwwexamplecom-trouble/) is redirecting to the www using 302. HTTP Headers and body of the reply are:

HTTP/1.1 302 Found
Date: Thu, 08 Jun 2006 05:39:04 GMT
Server: Apache/2.0.46 (Red Hat)
Location: http://www.sitepoint.com/blogs/2005/06/14/examplecom-vs-wwwexamplecom-trouble
Content-Length: 343
Keep-Alive: timeout=12, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

302 Found

Found

The document has moved here.

Apache/2.0.46 (Red Hat) Server at sitepoint.com Port 80

T2DMan May 8, 2006 at 7:56 am

I asked the question regards what htaccess to have for inner directories. Since htaccess in inner directories supercede the htaccess in the root. I now successfully use the following style:

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

Two domains pointing to same hosting account

I came across a situation where two domains were pointing at the same hosting account. I had to effectively change the url to the proper one if the domain name was the wrong one. By not having the ^ at the start of domain2, I was able to cater for both the non www and www versions of domain2.

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

Further examples of redirects, including isapi redirects can be found at my forum:
Non www ro www 301 redirects

Anonymous May 8, 2006 at 1:55 am

://www.example.com

Domains March 13, 2006 at 2:07 am

In the public_html .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
RewriteEngine on
Options +FollowSymlinks
Options +ExecCGI

In every other .htaccess present:

RewriteEngine on
Options +FollowSymlinks
Options +ExecCGI

Someone let me know if the last three lines of the first code block are not necessary – don’t have time to test it now.

T2DMan October 30, 2005 at 10:42 pm

I have no problems with coding for www to non www from the root htaccess. But when I have htaccess in any of the subdirectories, I cant seem to get the non www to www working.

Does anyone have some code sugggestions.

Z October 26, 2005 at 6:14 pm

Dear Dan, thank you for this blog.
A question. My mydomain.com and http://www.mydomain.com used to have 5/10 PR – both of them. As of today mydomain.com is ranked 0 with no links to it. http://www.mydomain.com is 5 with about 200 links. I promoted http://www.mydomain.com and obviously need to use redirect 301 to redirect to www version. My hosting company doesn’t do server redirect, but they say it can be done programmatically. Question: if I use redirect 301 to redirect mydomain.com to www version, could I potentially end-up with 0 PR for www version as well? Is it possible? Please help. I am so exhausted by these domain technicalities and terrified to do something really stupid that could affect my site, a love labor of 5 years…

Domains October 14, 2005 at 10:42 pm

Solution found to restore FP extensions:

Find every .htaccess file you can in File Manager (there are many) and place the following in it:

RewriteEngine on
Options +FollowSymlinks
Options +ExecCGI

It’s time consuming, so it would be good if someone could write a script to automate this.

Domains October 13, 2005 at 10:04 pm

I’ve only been able to redirect to http://www.mydomain.com and not simply mydomain.com with this redirect. Also, it disables my FrontPage extensions. I tried inserting the lines “RewriteEngine on
Options +ExecCGI” suggested at http://www.searchenginecollege.com/2005/07/dupe-domain-indexing-dilemma.html in various places within the .htaccess file, but the FP extensions remain disabled. What else can I do, as it appears I may have been hit with this dup penalty?

Anybody have the answer to this?

Anonymous July 4, 2005 at 5:50 pm

I’ve only been able to redirect to http://www.mydomain.com and not simply mydomain.com with this redirect. Also, it disables my FrontPage extensions. I tried inserting the lines “RewriteEngine on
Options +ExecCGI” suggested at http://www.searchenginecollege.com/2005/07/dupe-domain-indexing-dilemma.html in various places within the .htaccess file, but the FP extensions remain disabled. What else can I do, as it appears I may have been hit with this dup penalty?

Kalena Jordan July 4, 2005 at 6:32 am

Just a note for the Front Page users out there, implementing this code will break FP extensions and CGI scripts, UNLESS you include this code in your file:

# -FrontPage-

RewriteEngine on
Options +FollowSymlinks
Options +ExecCGI

thanks for the code Dan!

fabrizio June 23, 2005 at 1:27 am

Sorry folks, obviously you have to replace my own domain name with yours… sorry, I cut and pasted here my actually code.

Best,

fabrizio June 23, 2005 at 1:24 am

Another way to do it in PHP is to include the following code in your index.html page before anything is displayed:

if (ereg(“^virtualsheetmusic.com”,$HTTP_HOST)) {
$destinowww = “http://www.virtualsheetmusic.com”.$REQUEST_URI;
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: $destinowww”);
exit;
}

Octal June 20, 2005 at 9:19 am

www may be deprecated by someone somewhere, but not with users.

Hence the promotion of no-www.org as an educational and information source.

DanThies June 16, 2005 at 10:42 pm

www may be deprecated by someone somewhere, but not with users.

Nick, you’re absolutely right that someone has to discuss this stuff from both sides. I was just trying to provoke you into posting a comment, and it worked, but you really ought to consider that “official blog” branding idea. The TW thread I linked to was 99% about playing defense on this, and no doubt helped a lot of people.

Nerveman June 16, 2005 at 7:45 am

Must learn to use BBcode! :)

Nerveman June 16, 2005 at 7:43 am

I know Google differentiates between the two. My site nervecentral.com worked both with the www and without. I always submitted my site to other websites without the www (e.g. http://nervecentral.com) and I ended up with a Google PageRank of 5 at http://nervecentral.com and 1 or 2 at http://www.nervecentral.com. Now I redirect all www links to no-www and I still have my PageRank of 5 and most users don’t notice a thing.

Octal June 15, 2005 at 8:15 am

As previously posted, www is deprecated Redirect to no-www :)

Kaystarmaker June 15, 2005 at 6:31 am

i actually posted a thread about this a couple of days ago:
http://www.sitepoint.com/forums/showthread.php?t=271600

sadly, it got about the same anounth of replies at this blog already has :)

i’d rather redirect the www to the no-ww, just for aestetics :)

cranial-bore June 15, 2005 at 4:26 am

Tiara you can have the best of both worlds. By redirecting users to the preferred version they will still get the content regardless of what they type, but you won’t be competing with yourself for ranking.

Tiara June 15, 2005 at 12:20 am

Gah! Please, keep it the way it is.

Not everyone will remember whether your website “canonically” has the WWW or not. Many times I’ve been to websites where one version works and the other version doesn’t. It’s useless, and highly annoying.

My domains work both ways and it hasn’t affected my search engine rating. What affects it? CONTENT. Not some arbitary “www”.

Keep it easy for the users – they matter the most. No point trying to butter up search engines when the ultimate targets only get ticked off.

wwb_99 June 14, 2005 at 8:21 pm

I, myself, would redirect the other way (http://no-www.org/)

But in any case, to do it on IIS:
1) Make a new virtual site listenting to, say, http://www.example.org. It can be set to any folder imaginable.
2) Go into the properties for said site.
3) Under the home directory tab, change it from “a directory on the local machine” to “a redirect url.” Put in a legitimate url, like example.org and it will start pushing visitors over there.

Nick W June 14, 2005 at 8:19 pm

>>*Hi, Nick, just trying to boost your rankings for a targeted search term.

Go right ahead Dan, but you’ll note that it’s tough to describe how to counter such things without explaining how to do them…

timhodgson June 14, 2005 at 7:33 pm

Anyone know how to do the redirect, as shown in the Apache example above, on a Windows based server with IIS running?

DanThies June 14, 2005 at 6:26 pm

Just a note to all, I can also see the goofy BBCode [url] tags in the post, but I am powerless to remove them. SitePoint’s blogging system is based on their forum system which insists on slapping [url] tags on without permission no matter what options a person uses when posting.

Comments on this entry are closed.

{ 1 trackback }