By Dan Thies

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

By Dan Thies

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.

  • 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.

  • timhodgson

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

  • Nick W

    >>*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…

  • 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.

  • Tiara

    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.

  • 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.

  • Kaystarmaker

    i actually posted a thread about this a couple of days ago:

    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 :)

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

  • 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.

  • Must learn to use BBcode! :)

  • 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.

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

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

  • 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”);

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


  • Kalena Jordan

    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!

  • Anonymous

    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?

  • Pingback: Watch Out - Canonical URL Bloopers()

  • Domains

    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?

  • Domains

    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.

  • Z

    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…

  • T2DMan

    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.

  • Domains

    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.

  • Anonymous


  • T2DMan

    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

  • dealwave

    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


    The document has moved here.

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

  • pepa

    if i yous some web site its not work

  • Gary LaPointe

    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!


  • 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.

  • Anonymous


    k 12


  • RonnyStalker

    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


  • ayşe

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

  • Irish Jim

    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.

  • Anonymous


  • Anonymous


  • cristobal

    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

  • adrian felipen acosta

    hello what estan bien yo mal adios

  • ghulab


  • ghulab

    i want to in my yahoo acount

  • www.beautywalk.com/

  • 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.

Get the latest in Entrepreneur, once a week, for free.