WWW or No WWW is Not the Same! Fix with Htaccess 301 Redirect

Geeky SEO Made Easy
Geeky SEO Made Easy

This is an extremely important and yet simple to implement SEO tip about those “w’s” you often see in a web address. This will seem basic to many people, but it is shocking how often it is misunderstood, handled incorrectly, or overlooked. If you do not have this handled correctly this could make a huge improvement in your SEO efforts.

This is not just about whether somebody can arrive at your website by typing either domain.com or www.domain.com. This is about how Google and other search engines may see it as duplicate content, because it is actually the same thing in two locations. It is also about how all of the links pointing to these duplicate versions of your website are treated, and their value split in two – thus diluted. It will not cause a penalty imposed by the search engines, but there is still a real penalty to it, all the same.

Either version of www or non-www is fine, but it is important to choose one version and funnel your efforts toward the chosen version. If your website has more high quality existing links pointing to one version, that is the right one to use! If you don’t know, be sure to check both versions with a tool like Open Site Explorer.

Don’t Let the Big “Canonicalization” Word Scare You

Relax! I will make this easy for you. The abbreviated Murnahan version is this: Canonicalization means there is just one outcome for multiple possible actions. In this case, it means telling search engines to favor the outcome of your choosing (“www.” or no “www.”).

That big and scary word, “canonicalization“, reminds me that everybody is not familiar with technical SEO (search engine optimization) issues. There are even fewer people who understand and enjoy things like web server architecture, DNS, htaccess, 301 response codes, and other geeky delights which make me excited to wake up in the morning. Yes, I truly enjoy the geeky details of how this Internet works. I hope to make this easy enough that you will enjoy it, too! Well, I will at least make it easy, and I’m even going to provide a simple tool so you can check what your website is saying to the search engines.

WWW. is a Different Domain

When you go to a website, you will find that some of them use “www.” in front of the domain name (example: www.awebguy.com), and some of them do not. It is very common that both options will take you to the same place on the Internet, or at least the same information. That still does not mean search engines see it the same way as humans.

You can skip right to the bottom of this article to read the fix for this, but I think you will benefit by first understanding what is wrong, and why you should fix it.

Note: Even if both versions of www or without www show the same content (web page, video, image, etc.), the problem is not solved. It is common for web hosts to direct both versions to the same place using DNS (domain name service), but that is not the same as a 301 redirect telling search engines which version is the authoritative domain where the content should be indexed.

It is important to know that the domain name (example: awebguy.com) is the “root domain”. Anything coming before the awebguy.com, such as ftp.awebguy.com, pop.awebguy.com, smtp.awebguy.com and etcetera denotes a SUBdomain. Yes, of course, this includes www.awebguy.com, because it is a subdomain, too! An easy way to drive this home is to go to mail.google.com or to www.google.com … they are clearly different.

Now that we understand this point, let’s think of the www and non-www versions as two completely different domains. If somebody links to your website (and let’s hope they will) which one should they be linking to? Using a 301 redirect will actually reflect the correct address in the browser address bar, making it more likely that they will choose the right version when they want to link to your website. That is because before your web server even sent the page to the person visiting your website, it knew which version to send. In the event that somebody gets it wrong, a 301 redirect will tell search engines that the content they linked to is actually at the other location where it should be indexed.

Note: In order to know for certain what your web server is telling people, you must check your server’s HTTP response headers. Don’t worry, I made you a handy little tool to check your website.

What you want to know is whether the header begins with a “HTTP/1.1 200 OK” response, or a different response such as “HTTP/1.1 301 Moved Permanently”. Only one of the versions will return the 200 OK, while the alternate version may return something else … and perhaps even something unexpected. I made this really easy to check your server’s response headers here:

Enter a URL:

An easy way to see this in action is to type my web address into a browser with either version. If you type it in without the “www”, my web server will know what you meant, and it will deliver the document (web page) at the proper address at the www subdomain – with a “200 OK” status. This will also work similarly for every page on the domain / subdomain, because I use a 301 redirect that simply redirects everything at awebguy.com to its exact equivalent representation with the correct www address.

The SEO “WWW” Fix: HTACCESS and 301 Redirect

Since many people do not configure and manage their own web servers, this is the easiest fix for most websites. If you have access to your main server configuration, use that, but this is simply not the case for most website owners. This solution uses very simple “distributed configuration files” known as “htaccess” which allow you to configure functions on a directory level.

OK, now that I drove you out of your comfort zone with some big techie language, just breathe slowly and get your heart rate back to normal. I am not going to force feed you a bunch of web programming. The fix is actually quite easy, or at least it will be easy if you pay attention. If you own a website and any of this is just too complicated, it would be like owning a car and not knowing how to put gas in it. Should that person really be driving? This is not like rebuilding your car’s transmission … it is like filling it with gas.

The “htaccess” is just a simple little text file you can create and edit with a text editor such as Notepad, SimpleText, or Vi. If you already have an existing htaccess file, you may simply edit it to include additional functions at the bottom of the existing content. Don’t be afraid of it, because it is really not very tricky. It may sound tricky when you consider all the things it can do, but it is normally just a small file with a minimal amount of text in it.

Htaccess is a configuration file that tells your server certain things to do when people ask for your web pages or other website content. It can be used for functions such as password protecting a directory, blocking selected people from accessing your website, and much more. The file name does not look like a lot of them you may see, such as hello.txt or mynameisfred.html, but don’t let that scare you. The htaccess file will begin with a dot (yes, a dot … like this one .) and the full file name is actually “.htaccess“.

You can have multiple of these “.htaccess” files within your website, but the one we are talking about is in the “root directory”. Stop! Don’t get frustrated … that just means it is right there in the same place where your home page and other files are. For example, the file http://www.awebguy.com/murnahan.pdf is in my root directory, but if it was at http://www.awebguy.com/other-directory/murnahan.pdf it would be found in the “other-directory” directory.

If you do not already have any .htaccess files in your website, don’t worry. You can just create one from scratch with a text editor, save it to your computer as htaccess.txt, and then upload it to your website and rename it “.htaccess”.

Within this magical .htaccess file, it will look almost just like plain old English language, and should not be overwhelmingly technical. I will use my own domain name for the examples, but you would of course want to change that to your own. Well, unless you want to redirect your website visitors to my blog, and that is fine, too. There is a lot you can do with this, but I don’t want to explode any heads with all of this technical junk. Technical junk really is like using explosives, sometimes!

I mostly want to explain how to create a 301 Permanent Redirect from either your www to non-www or from non-www to www. In order to do this, all it takes is either editing your existing htaccess file and adding the selected version below into the file, or creating a new htaccess file with the same. You can change the domain to any domain you like, but you will probably want to change it from mine.

Remember to always create a backup copy of anything you edit. If you mess it up and you want me to play a sad tune on my violin, I get paid overtime for that! 🙂

Example of a 301 Permanent Redirect of WWW to Non-WWW

This is the code to use in your htaccess file for redirecting content to the non-www version of your website.

RewriteEngine On
RewriteBase /
RewriteCond % ^www.awebguy.com [NC]
RewriteRule ^(.*)$ http://awebguy.com/$1 [L,R=301]

Example of a 301 Permanent Redirect of Non-WWW to WWW

This is the code to use in your htaccess file for redirecting content to the www version of your website.

RewriteEngine On
RewriteBase /
RewriteCond % ^awebguy.com [NC]
RewriteRule ^(.*)$ http://www.awebguy.com/$1 [L,R=301]

There are many other handy things you can do with this, and some examples are below. Note that each of these should be created on a single line within the htaccess file.

Example of a 301 Permanent Redirect (note the local address then a space, and then the new URL)

RedirectPermanent /thispage2.html http://www.awebguy.com/thatpage2.php

Example of a 302 Temporary Redirect (this is the same format as 301, but without the “Permanent”)

Redirect /thispage.html http://www.awebguy.com/thatpage.php

Example of Custom 404 (page not found)

ErrorDocument 404 http://www.awebguy.com/404-file-name-here

Know Your Server’s Response Codes!
Even the difference in a slash at the end of an address makes the difference of a good “200 OK” response or a “301 Moved Permanently” or worse. You should be aware of the difference it makes.

I will reiterate … I made this really easy to see what your server is returning for any given web address. Check it here if you are not entirely sure:

Enter a URL:

Here are some additional resources about htaccess usage:

.htaccess on Wikipedia

Comprehensive guide to .htaccess

Well, there you have it … my answer to www vs. non-www and how to fix it easily with 301 redirect using htaccess. I told you I would make it simple. I welcome your feedback!

SEO Tip: Trailing Slash, Canonicalization, and Google

Google, SEO, and Trailing Slashes
Google, SEO, and Trailing Slashes


I am going to give you a helpful SEO tip that you can put to use fast and easy. It is a common error that can make a big difference in your search engine optimization efforts, and it has to do with canonicalization. Don’t let the big word intimidate you, because I will break this down and make it very easy to understand.

I could get really deep into the issues of your sitemap format, .htaccess files, rel=”canonical” tags, server configuration, and a squillion other things, but not this time. I want to give you the “low hanging fruit” that anybody can put to good use, starting immediately.

The Difference in a Slash or No Slash

Did you know that there is a significant difference between a web address that has a slash at the end and one that does not have a slash at the end of it? I don’t want to confuse anybody, so I will give a visual example of what I mean. I will show you two web addresses (URL) that look very similar, and will both land you in the same place, but they are actually very different. My sample web addresses are as follows:

http://www.awebguy.com/seo-lessons/
http://www.awebguy.com/seo-lessons

As you can see in my example above, one of these addresses has a trailing slash (“/”), and one does not. So, let’s examine the important difference that the slash at the end of a URL makes. For you technical folks, it makes the difference of returning a “200 OK” status code or a “301 Moved Permanently” (or other) status code when the page is requested. I will try to explain this a little better for the non-techie people, because I really want this to make sense, and I want it to help you.

Note: In order to know for certain what your web server is telling people, you need to know your server’s HTTP response headers. Don’t worry, I made you a handy little tool so you can see the difference. I will also show you how to tell the same thing with Google Webmaster Tools.

What you want to know is whether the header begins with a “HTTP/1.1 200 OK” response, or a different response such as “HTTP/1.1 301 Moved Permanently”. Only one of the versions will return the 200 OK, while the alternate version may return something else … and perhaps even something unexpected, like a “404 Not Found”. I made this really easy to check your server’s response headers here:

Enter a URL:

I am using Google in this instance, because we all care about Google, and I am using Google Webmaster Tools to illustrate the point. When search engines visit your website, they receive what is called an “HTTP status code” from your web server which tells them the status of the URL. A status code you have surely seen is “404 Page Not Found”, but there are a lot of other server status codes, too. The two which I am primarily addressing here are “200 OK”, which is the one you want search engines to see, and “301 Moved Permanently”, which tells the search engines that your page is not at that address, but your web server knows where to find it.

Below are screenshots from within Google Webmaster Tools to show what Google sees with my two sample addresses. The images below show the status codes that Google received for each of them. Note the address that Google fetched, and the status code in each of these images. In the instance with the trailing slash, the “200 OK” was returned, and Google continued with fetching the page. In the second image, Google was told that the page had “moved permanently”, and where to find it.

Googlebot Fetch with 200 Status Code
Googlebot Fetch with 200 Status Code

Now let’s look at the 301 status code. Notice the difference in how it tells Google that the page has moved, and where to find it.

Googlebot Fetch with 301 Status Code
Googlebot Fetch with 301 Status Code

A 301 status code is still better than having it return a “404 Page Not Found” error, but far worse than returning a “200 OK” status. Perhaps it shouldn’t surprise me, but I have actually witnessed “webmasters” handle this with 404 and 302 status with a lot of websites as well. Notice that I used the term “webmasters” very loosely, and this definitely does not reflect the work of a “master”. Yes, even on the modern Internet of 2011, people still screw things up, horribly!

Slash or No Slash in URL and Duplicate Content

Either of the URL versions is “correct” to use, but you should choose one, stick with it, and configure your website and your links accordingly. I have seen a lot of cases where people have their website configured to return a “200 OK” status code for both versions, but that is a horrible idea. The reason is that if both addresses return a 200 status, you are telling Google that the content actually exists in two places. That would result in duplicate content, which Google deals with pretty well, but does not like. It also dilutes your efforts for building links.

The Easiest Novice Fix for Canonicalization

This is surely very confusing for a lot of people, or the problem would not exist. However, there is one small part of this issue which even a novice can work to improve. You may not get it all fixed with this, but it will be a good start to fixing a common mistake.

Whether it is a link from other websites, or links between pages on your website, you should always link to the version which returns a “200 OK”, because that is where the page actually resides. Google and other search engines can be quite accommodating, but there is a qualitative and quantitative difference in doing this right and doing it wrong. With all of the competition on the Internet, it is worth getting things right, as much as possible.

The right or wrong version to use depends on your website, and what the URL represents. You see, an address that ends without a slash is typically used for a file, while an address with a slash denotes a directory structure (but not always). The right version to use will vary, but the most important thing to know is to always use the URL which returns a “200 OK” status, whichever that is.

In the case of content management and blogging systems like WordPress, the trailing slash is often used, and the correct status code is returned. However, even in instances where it seems that it is all done for you, there are many cases where you, or others, may link to content manually and use the wrong format.

How to Fix Trailing Slash and Canonicalization Errors

Fixing your canonicalization errors does not need to be a huge headache. Since this can make a big difference in your search engine ranking, it is very worthwhile to fix it. The “Official Google Webmaster Central Blog” has a useful article about this issue, and it is titled “To slash or not to slash“. I think it is worth a read. Another, more effective, alternative is to hire a good SEO to help you to know what you didn’t know, and to fix the things which are holding you back from ranking higher in search engine results.

What I have described is an easy mistake, and one which may be costing you, big! I hope that you will give this your attention, and that you will use it to improve your search engine ranking effectiveness.

As always, your comments, questions, compliments, gripes, complaints, and bellyaches are all welcome here on my blog.

If you don’t like what I have to say about this, I welcome you to look at my HTML source code to see if that helps you any. 😉