Many website owners have a small technical issue with their site(s) that they don't even realize, and when left uncorrected, can severely hurt search engine rankings. This situation occurs when the one or more pages can be accessed via several different URL's.

For example, the following URL's may seem like they are the same page, but to a search engine, are actually different pages:

What are some of the issues you can face when this occurs?

If people link to your site inconsistently (which will happen sooner or later), different versions of the same pages can get indexed in search engines. This forces the search engines to choose the best URL to rank, or Canonical URL. It's never a good idea to leave this decision up to search engines, because it can trigger the following problems that will hurt your rankings:

  • Search engines attribute authority to a site based on the incoming links from other sites.  Link juice or PageRank (the benefit of these inbound links) may be divided among different versions of a page instead of being allocated to just one page. This will cause one or more versions of a page to not rank as well as they could.
  • Duplicate content issues can occur. Search engines may pick one page to rank and drop any others that carry identical/similar content.
You should be in control of what versions of your site and pages get indexed, and not leave it up to search engines to decide.

WWW vs. Non-WWW Versions of Your Site

Let's take a look specifically at the first two examples from our list of URL's above, the www and non-www versions of a site, because these are the most common, and easiest to fix.

In many aspects of ranking a site, search engines treat different subdomains on a site as if they were different domains entirely. Technically the www and non-www versions of your site are different subdomains, even though they have the same exact content.

If you do a search in Google, you'll often see results where some have the www version and others have the non-www version of the same site. Not good. Regardless of whether these rank well or not, a site's rankings can be improved by fixing this. 

First take a look at your site, and see if you can access it via both and where is your domain name. If both versions end up at the same URL, then you're fine and you don't need to continue reading. However if both versions work, and neither redirects to the other, then read on.

Choose a Version

First, you need to pick a version of your site to use. Do you want people to visit or There are good reasons to choose either one. The non-www version takes up less space and can offer more real estate on business cards, promotional materials, etc., but on the other hand, most people are trained to use the www version and will type that into a browser by default. Whatever you choose, be consistent in your usage, in everything from your site's internal linking to your marketing collateral.

The Solution: 3 Lines of .Htaccess Code

There is a quick solution that most website owners shouldn't have any problem implementing. The following is for sites on an Apache server, which most sites are. (If your site is on a Microsoft server, you'll most likely have to ask your site administrator configure it to do the equivalent for you.)

First you will need to either edit, or create an .htaccess file. If you're not familiar, .htaccess is an Apache configuration file that goes in the public root folder of your website (the same directory where your site's index file is). If you already have an .htaccess file, back it up before making any edits. If you don't have one, simply open any text editor (Notepad, TextEdit, etc.) or html editing program (Dreamweaver, etc.) and create a blank file named .htaccess. Be sure to leave at least one blank line at the end of the file.

To use the www version of your site, insert the following near the beginning of your .htaccess file (switch to your domain name):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com
RewriteRule ^(.*)$$1 [R=301,L]

To use the non-www version of your site, insert the following near the beginning of your .htaccess file (switch to your domain name):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com
RewriteRule ^(.*)$$1 [R=301,L]

Then test it out and make sure it's working the way you want it to. If everything looks good, you're done!

Wasn't that easy?

April 29, 2008

Scott is the CEO and founder of Red Sand Marketing, a San Diego SEO and web design firm. A dynamic mix of marketer, designer, and developer, he thrives on all aspects of internet marketing and web development. Having been involved in search engine optimization and web design since 1996, he and his team consistently achieve top search engine rankings for clients in competitive markets, and have won multiple web design awards along the way.


In addition to the .htaccess method you may want to indicate which www or non-www method in the google webmaster tools.

What about the issue where I have a master hosting account, then have subdomains under it? For example, my main site is I have a subdomain called I also have pointing to that. Every now and then I'll see a search result that points to instead of Could I just do something like this:

RewriteCond %{HTTP_HOST} ^finearttouch\.harnesshouse\.com
RewriteRule ^(.*)$$1 [R=301,L]


Thanks, nice post will Sphinn.

Yay! Excellent first post on SEG. Thanks for the simple tips and for explaining them in detail. It really helps those of us who have no clue what you're talking about understand better. Plus, my freebie preview lesson helped me understand it even more. ;)

@Chris Estes: Yes, that is absolutely true, it's a decent backup option. I don't recommend relying on that or other third party solutions though because even though Google has the largest search engine market share, it won't solve your problems with other search engines, and Google could potentially revoke that option at any time.

@Glen Harness: Upon a quick glance at your code, that should work fine.

@Jeff Howard, @Rachel Phillips: Thanks!

Hey Scott! Nice to see you here (can finally see what you look like too lol I usually think of your Keanu Reeve's avatar on the DP forum when I imagine what you look like)

Great post and tips. I use the Enforce WWW plug-in for my WordPress' blog. A good solution for non-techie people who don't want to tinker around with the htaccess file

@Michael: Hey! Good to see you here as well. Sometime ask me about why I chose that avatar of Neo - it will make you laugh. Thanks! That's a great piece of advice for WordPress bloggers. Now if only there were plugins for websites in general. :)

OK, so what if I have other subdomains at the same level? For example, and are the same site, but and are different ones, but run from the same server. If I use the rule to rewrite as, will that affect resolution of URLs for the other sites?

I always think it's best to use the www version to maximize SEO inbound links. People are used to typing in the w's.


I think that your approach would be valid until a few months ago. Matt Cutts puts the question around two years ago. In fact Google gave different pageranks to theese URLs, but currently no. The back links, as well the pageranks, are the same if you search them either with www or not, or if you use index (or default).

Great tip - thanks! Took me less than 5 mins and your instructions made it super easy! www here we come....

Is there a way to verify the need? I checked about 30 pages on my website and they all had the identical PR, whether www or not. I know this was an issue a while back, and the pr was different on most of my pages (non www was lower). But things keep improving and I wonder if it is still necessary. Selecting the preference in Google tools may have made the difference for PR, but as was mentioned, other search engines may not have a handle on this.

@Ruy I've generally been thinking the same thing lately about whether this is necessary anymore (I do it on all sites I work on by default). Just this week though I ran a link search for a client that returned different results with and without the www subdomain. Weird

Hi Scott,

Great tip, but it doesn't work for me! Can you help?

Here's my code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^
RewriteRule ^(.*)$$1 [R=301,L]

I checked with my ISP and they're on apache.

I'm clueless.

Frak and Esoomllub,

Yes, I agree that we can find some differences with different tools. Even in the organic search the results may differ from a given search feature to other. But the point is: one URL had back links and PR, let's say, 4, and the other URLs had not back links and the PRs were zero. In addition, I suppose that the cited differences will disappear over the time.

@Janet: You shouldn't have any problems with subdomains because in most cases, rewrite directives of this kind in your main .htaccess won't affect your subdomains. As always, test things out first.

@Get Clickz Blog: Personally I would normally agree on using the www version, but there some good reasons for using the non-www version as well. Using the redirect mentioned above will forward all links to the correct version, and search engines will eventually pass on any link value to the correct version.

@Emily: You're welcome! Always glad to help. :)

@Ruy Miranda: I hear your point, but I would have to disagree. It's still important and valid to use this method for a number of reasons. While Google continually does get better with issues like this, I maintain my point that it's important to not leave it up to them, or any other search engine. You may see the same PageRank for sites with non-www and www, but I wouldn't rely on that information alone. The value of incoming links is much stronger when they are directed (or redirected) to the same version of the site. Keep in mind, Google isn't the only search engine. with sites that incoming links split between the two versions, I've seen rankings go up drastically (time and time again) within a short period of time of implementing only this fix, even recently. Also, it's simple a best practice to not have multiple versions of your site from a usability point of view, and it will make it easier for people to link to you.

@Frak, @Esoomllub: You may not see a huge problem with only 30 pages, but it's a lot easier to prevent SEO problems than to fix them afterward.


Great article. Have a questions.. when i search my site I only get results with not with the www
What does that mean? Thanks!

@Scott The site I noticed this with was a 19k page site. As I was saying though, this redirect is something I do by default on all sites that I am working on. Almost every site I've been brought in to do SEO work on though does not have this in place. As well, most of them don't have the basics of SEO in place, which means a quick boost in rankings is often easy to attain.

Thanks, Scott, I'd read about this before but the directions were confusing. Good tip from Chris about Webmaster Tools as well. When I tried this the first time, (and did it wrong), my Webmaster account noticed. Thanks again, Jill

Dear sears,

I have 5 web sites, and want to construct a web portal which will unify all sites in one (on new location, same IP) with new unique content. After this (constructing a new portal) want to redirect all this domains (301 redirection), to new one, we presume that this will not affect our position on Google, is it possible for us that Google bann us from index, because of redirecting 5 domains to one? I know that 301 is a legal, but I found different opinions, like

“If you 301 several different domains/web pages to ONE single page,
that ONE single page will get humped and dumped by google with no
apologies. DONT DO IT!

If you're already getting traffic from google, I would caution against
doing anything at all! If you do anything wrong with regards to
301/302/404, google will break it off in your culo and drop you so far
in the rankings that you will soon be on welfare.”

So if You be so kind to help I would appreciate.


We have two different point of view: to me, currently a page with and without www has a unique version, not two. Out the area of PR the content in the two URLs is not view as duplicity by any search engine.

We have several sites on both IIS and apache servers. On the apache server, we are running phpsuexec so we cannot use .htaccess, how would we go about doing the above fix?

I've applied this successfully for a few web sites, but they were all .com sites. When I tried to use it for a .net sire, it fails to work.

Is there something special about sites?

Great site!! Steps are very clear and concise. I would like to learn more about the difference among different tools.

This is a great bit of code. I too am a fan of not having a third party do all the work for me. I'm more of a personal responsibility guy myself.

I'd have to say this works well still.

Noticed many more links found in google after implementing and pr a month or so later up 1 level. It takes so little time, and like Scott says, why leave this decision to the SE?


Comments closed after 30 days to combat spam.

Search Engine Guide > Scott Allen > How 3 Lines of Code Can Improve Your Rankings