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.
If you liked this blog, share the love:



June 14th, 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.
June 14th, 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?
June 14th, 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…
June 14th, 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.
June 15th, 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.
June 15th, 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.
June 15th, 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 :)
June 15th, 2005 at 8:15 am
As previously posted, www is deprecated Redirect to no-www :)
June 16th, 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.
June 16th, 2005 at 7:45 am
Must learn to use BBcode! :)
June 16th, 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.
June 20th, 2005 at 9:19 am
Hence the promotion of no-www.org as an educational and information source.
June 23rd, 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;
}
June 23rd, 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,
July 4th, 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!
July 4th, 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?
October 2nd, 2005 at 11:11 am
[…] I’ve been pretty careful to ensure all of my websites land on a http://www.domainnameDOTcom or without the http://www. with just domainnameDOTcom. Not too long ago there were plenty of warnings explaining the importance of having your domain direct to just ONE version, not both. […]
October 13th, 2005 at 10:04 pm
Anybody have the answer to this?
October 14th, 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 +ExecCGIIt’s time consuming, so it would be good if someone could write a script to automate this.
October 26th, 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…
October 30th, 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.
March 13th, 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 +ExecCGIIn every other .htaccess present:
RewriteEngine on Options +FollowSymlinks Options +ExecCGISomeone let me know if the last three lines of the first code block are not necessary - don’t have time to test it now.
May 8th, 2006 at 1:55 am
://www.example.com
May 8th, 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
June 8th, 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 FoundThe document has moved here.
Apache/2.0.46 (Red Hat) Server at sitepoint.com Port 80November 17th, 2006 at 1:19 am
if i yous some web site its not work
November 19th, 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 http://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/
December 1st, 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.
March 9th, 2007 at 7:24 pm
!l$
jk,k
mùmùùmù
March 27th, 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.
May 26th, 2007 at 1:03 am
sqxdcxq
August 11th, 2007 at 3:49 am
sen elif ablanın düyününde nasıl giyinecen aşkım
February 6th, 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.
February 20th, 2008 at 4:21 pm
我是你哥
March 22nd, 2008 at 2:57 am
SDFGHJKLŞ
June 3rd, 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