WWW or no WWW is not the same! Fix with htaccess 301 redirect

Source: Internet
Author: User
Tags subdomain

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 inform people, but it is shocking how often it is misunderstood, handled incorrectly, or
Overlooked. If you do not have this handled correctly this cocould 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 shoshould 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 shoshould 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 example, example, example and etcetera denotes a subdomain.
Yes, of course, this parameter deswww.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 shoshould they be linking? 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 shoshould be indexed.

Note: In order to know for certain what your web server is telling people, You mustcheck
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:

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 representationwith
The correct WWW address.

The SEO "www" fix: htaccess and 301 redirect

Since login 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 wocould be like owning a car and not knowing how to put gas in it. shocould 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 filehttp: // www.awebguy.com/murnahan.pdf is in my root directory, but if it was
Athttp: // www.awebguy.com/other-directory/murnahanw.it wocould be found in the "Other-Directory"

If you do not already have any. htaccess files in your website, don't worry. you can 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 shoshould not be overwhelmingly technical. I will use my own domain name for the examples, but you wocould 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

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


Rewritecond % ^ awebguy.com [Nc]
Rewriterule ^ (. *) $ http://www.awebguy.com/#1 [L, r = 301]

There are using other handy things you can do with this, and some examples are below. Note that each of these shoshould 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 shoshould 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:

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 wocould make it simple. I welcome your feedback!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.