Get Paid to Participate - up to $1 per post!     Twitter     Facebook     Google+
Hosting Discussion
 

Hosting Discussion > Operating a Web Hosting Business > Promotion and Marketing > 301 Redirect NON WWW to WWW (or vice versa) - Good SEO technique!
forgot password?



Reply


Old
  Post #1 (permalink)   05-02-2011, 07:00 AM
HD Addict
 
NobleCloud's Avatar
 
Join Date: Feb 2011
Location: Exeter, UK
Posts: 115
Send a message via MSN to NobleCloud

Status: NobleCloud is offline
Some of you might wish to discover a really good SEO technique that is so simple to do. And yet helps your page rank on search engines such as google.

By default, you see, your site resides on both http://yourdomain.com and http://www.yourdomain.com

This means that search engines are going to take twice as long to index you as they are indexing content from both the WWW domain and the NON WWW domain. This will affect your page rank and will slow down the length of time it takes for you to get a PR quite considerably.

Also when people link to your page. Some might link to the NON WWW domain and others to the WWW domain. Basically this would cause your page rank to be different for each as some might link more on one than the other. In other words you're creating double the work for yourself and the search engine bots. The quick way to fix this is to permanently redirect one to the other. See below.

So, how to fix this? Well, I'm going to show you how you can create a 301 redirect from http://yourdomain.com to http://www.yourdomain.com (NON WWW to WWW). You can do this the other way round, and redirect from the WWW to the NON WWW if you wish.

The technical term for this type of redirect is "Canonical Redirect".

All you need to do is create a .htaccess file and place it in the PUBLIC_HTML folder (make sure you call it "."htaccess, with the period...think of it as a .htaccess extension. Whatever you do, don't upload it as htaccess.txt!). You will also need to make sure that mod_rewrite is enabled on your server (you can ask your hosting provider about this if you're not sure).

Once you've done that simply add the following code to the .htaccess file. This code will tell your site to redirect any visitors who visit your site without inputting the WWW to your WWW domain. Anyway, I don't want to confuse you any more. So here's the code...make sure you change yourdomain.com to your domain.

Code:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourdomain.com [nc]
rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]
 
 


Old
  Post #2 (permalink)   05-02-2011, 11:50 AM
HD Wizard
 
Join Date: Mar 2005
Location: Atlanta, GA
Posts: 2,264

Status: handsonhosting is offline
Careful with that code, you can find yourself in a redirect loop.

Code:
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^(.*)\.yourdomain\.com$ [NC] 
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
The above is the one that should be used.
__________________
Emerson Nogueira
http://www.HandsOnWebHosting.com
cPanel Web Hosting, Domain Registration, Managed VPS Servers
 
 


Old
  Post #3 (permalink)   05-02-2011, 01:15 PM
HD Addict
 
NobleCloud's Avatar
 
Join Date: Feb 2011
Location: Exeter, UK
Posts: 115
Send a message via MSN to NobleCloud

Status: NobleCloud is offline
Surprisingly enough, for me anyway, the code I stated is the only one I've ever got to work WITHOUT getting myself into a redirect loop. I've tried many codes before. The one I use has worked out the best, surprisingly.

So I'm afraid I'll have to disagree with you on that one. Sorry.
 
 
 


Old
  Post #4 (permalink)   05-02-2011, 11:55 PM
HD Wizard
 
Join Date: Mar 2005
Location: Atlanta, GA
Posts: 2,264

Status: handsonhosting is offline
No worries. If it works for you, that's all that matters.

The reason for the extra !^(.*) has to do with subdomains. The last thing you'd want is a subdomain for your same domain being redirected off to some other location. So by entering that portion, that ensures that your subdomains don't get fired off to the main domain. It also saves time on your Server (which means faster website for your visitors) as the system does not need to check to see if "www" is present or not. In your example, even if WWW exists, it will rewrite the URL. That's an extra few milliseconds that could be used to download data to the visitor rather than wasting time looking up to redirect.

Every millisecond counts.

Also, adding the "L" on the last line rather than an "nc" (which has to do with case), the L means it's the last line to process for that Rewrite Condition. It helps the server know that it doesn't need to keep reading the rest of the .htaccess file for this particular redirect.
__________________
Emerson Nogueira
http://www.HandsOnWebHosting.com
cPanel Web Hosting, Domain Registration, Managed VPS Servers
 
 


Old
  Post #5 (permalink)   05-03-2011, 03:01 AM
HD Addict
 
NobleCloud's Avatar
 
Join Date: Feb 2011
Location: Exeter, UK
Posts: 115
Send a message via MSN to NobleCloud

Status: NobleCloud is offline
That's useful to know. Thanks.
However I'll stick to my current setup for now as it's the only one I've ever got to work.
 
 
 


Old
  Post #6 (permalink)   05-23-2011, 12:52 AM
HD Newbie
 
Join Date: May 2011
Posts: 8

Status: taniasharma is offline
Nice post.
Google count different www or without www both type of websites. With www is a standard form of website. If your server show your domain name without www, you can use 301 Redirect to redirect your website without www to with www domain name.
 
 
 


Old
  Post #7 (permalink)   06-27-2011, 08:37 AM
HD Newbie
 
Join Date: Apr 2011
Posts: 11

Status: cycom22 is offline
Quote:
Originally Posted by handsonhosting View Post
Careful with that code, you can find yourself in a redirect loop.

Code:
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^(.*)\.yourdomain\.com$ [NC] 
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
The above is the one that should be used.

where should this code be placed?
 
 
 


Old
  Post #8 (permalink)   07-01-2011, 11:29 AM
HD Wizard
 
Join Date: Mar 2005
Location: Atlanta, GA
Posts: 2,264

Status: handsonhosting is offline
That should be placed at the top of your .htaccess file in your site. Generally inside the /public_html or /docs folder.
__________________
Emerson Nogueira
http://www.HandsOnWebHosting.com
cPanel Web Hosting, Domain Registration, Managed VPS Servers
 
 
 


Old
  Post #9 (permalink)   07-01-2011, 09:02 PM
HD Addict
 
Join Date: Nov 2010
Posts: 146

Status: hostloc is offline
you don't have to place at the top of .htaccess, just place it anywhere but make sure it's the .htaccess in your website root.
__________________
Hosting Reviews | Hosting Coupon
Find the most suitable web hosting for your site
 
 
 


Old
  Post #10 (permalink)   07-03-2011, 07:43 AM
HD Addict
 
NobleCloud's Avatar
 
Join Date: Feb 2011
Location: Exeter, UK
Posts: 115
Send a message via MSN to NobleCloud

Status: NobleCloud is offline
Yes.
If you have, for example, Frontpage extensions installed on your domain you could put at the bottom (or at the top) of your .htaccess file in root.

So, it can go anywhere in the .htaccess file providing, as hostloc said, that it's in the root .htaccess (or the default one in your public_HTML folder).
 
 
 


Old
  Post #11 (permalink)   07-15-2011, 03:28 PM
HD Newbie
 
Join Date: Jul 2011
Location: Netherlands
Posts: 38

Status: RobinF is offline
So what do you guys prefer, anyway? Redirecting to a WWW adres or a non-WWW adres? So far on my personal sites I've always used the non-www adres since I feel the WWW in a URL has become kind of obsolete. But what is the best route to take and why?
 
 
 


Old
  Post #12 (permalink)   07-15-2011, 11:52 PM
HD Wizard
 
Join Date: Mar 2005
Location: Atlanta, GA
Posts: 2,264

Status: handsonhosting is offline
Personally, we keep the "www" in the domain name. You'd be amazed at how many NEW people to the web still type the "www" in the domain names. If you setup your redirection correctly and also tell google webmaster tools (and bing tools) the correct format for your domain (with or without the WWW) then you'll have no issues no matter what way you do it. You just need to pick one way, and stick with it.
__________________
Emerson Nogueira
http://www.HandsOnWebHosting.com
cPanel Web Hosting, Domain Registration, Managed VPS Servers
 
 


Old
  Post #13 (permalink)   07-20-2011, 04:09 AM
HD Newbie
 
Join Date: Feb 2011
Posts: 18

Status: outshinesol is offline
I got some valuable rewrite rules and update them. This is really good to work with this I convert my dynamic links into static and get more search engine friendly URL. I like to share this link with you. I hope this will help to many as it helps mine http://www.mattcutts.com/blog/the-li...01-that-could/
__________________
Vikas Arora
Web hosting India, SEO Services India
 
 
 


Old
  Post #14 (permalink)   09-07-2011, 05:12 AM
HD Newbie
 
Join Date: Feb 2011
Posts: 20

Status: TemplateSpin is offline
I use 301 redirect when I decide to put www on my site. And I also used this technique to avoid duplicate content.
__________________
TemplateSpin.com Professional Web Design Services
Custom Web Designs & Ready Made Unique Templates
Logos, Banners, Folders, UI Designs & Web Coding
 
 
 


Old
  Post #15 (permalink)   09-26-2011, 09:59 PM
HD Newbie
 
Join Date: Dec 2010
Location: Maryland
Posts: 19

Status: jewin is offline
Also checkout rel="canonical", which can be used for the same effect. Checkout the video Matt Cutts, About rel="canonical".
__________________
Improve Your Website Security at HostingArmor.com
 
 
 
Reply
Previous Thread Next Thread


Thread Tools

New Post New Post   Old Post Old Post
Posting Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Sponsored By: