Using Mod-rewrite to Redirect Non-www URL to www URL

Did you know the URLs “www.The SEO Blogger.com” and “http://The SEO Blogger.com” are distinct URLs and are treated differently by the search engines?

This has to do with URL canonicalization. What’s URL canonicalization you ask?

According to the head of Google’s Webspam team, Matt Cutts, URL canonicalization is “the process of picking the best url when there are several choices”:

* www.The SEO Blogger.com (same as www.The SEO Blogger.com)
* The SEO Blogger.com (same as http://The SEO Blogger.com)
* www.The SEO Blogger.com/index.php
* The SEO Blogger.com/home.asp

Most people think that those are the same, but on technical term, they are NOT!

*Can you see how the URLs are different, even though they may serve up the same web page?

Luckily, after a major update to “Big Daddy,” Google now is able to detect which one is the best URL for you/your website. However, you do have to help Big Daddy in the process.

How do you help make sure Google pick the URL that you want?

Well, for your internal linking, the URL that you use should be ‘consistent’. For example, if I’m planning to use “http://The SEO Blogger.com” as the consistent URL form for all of my EXTERNAL inbound links, it’s wise to use that URL form in ALL my internal linkings, as well. And, as you can see, I have done just that.

*Note: the reason you don’t want to have half of your links pointing to “http://yourdomain.com” and the other half to “http://www.yourdomain.com” is because you do NOT want to split the value of those links up. You want to have one ‘consistent’ URL form, so that your website (page rank) will receive the FULL benefits of ALL the links, not just HALF of them.

–But here’s the problem, you only have control over the URL form of those external/internal links if you are the one who’s placing those links (URL form). For many other people who link to your website, you cannot control which URL forms (http://www. or http://) they will link to you.

Thus, in order to receive FULL benefit of consistent URL, you need to set up a 301 permanent redirect from one URL form to another, which is pretty easy–as shown below:

Using Mod Rewrite to Redirect “Non-www” URL (http://) to “www” URL (http://www.)

In order to do this, you must have access to the .htaccess file via FTP or CPanel File Manager. Most Apache web server (Linux hosting) has this .htaccess file. If not, you can create and name the new file .htaccess and place it inside the root directory of your domain (e.g. public_html/.htaccess).

You must edit/add the following mod-rewrite script to your .htaccess file to redirect “http://” to “http://www.”:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ www.%1.%2%{REQUEST_URI} [R=301,L]

The above script will redirect:

http://yourdomain.com to http://www.yourdomain.com

Redirecting “www” URL (http://www.) to “Non-www” URL (http://)

This is the simple mod rewrite script I use to redirect “http://www.The SEO Blogger.com” to “http://The SEO Blogger.com“:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.TheSEOBlogger.com [nc]
RewriteRule (.*) TheSEOBlogger.com/$1 [R=301,L]

*Note: you should change “The SEO Blogger.com” to YOUR WEBSITE NAME! Also, if you have sub-domains, the above script will also work. Also, by ‘default’, I think WordPress gives your site URL as “http://www.yoursite.com.” If you want your site to be in “http://” URL form, you, of course, have to go to “OPTION ->General” and update your site URL to “http://yoursite.com” instead of “http://www.yoursite.com.”

Anyway, here is a live demo of those two scripts at work:

http://mint-tree.com >>> www.mint-tree.com
http://www.TheSEOBlogger.com >>> TheSEOBlogger.com

By using either one of these mod-rewrite scripts, you can have a consistent URL in your linking campaign. Now, you don’t have to worry what URL form others have used to link to your website. Now “http://” and “http://www.” are ‘consistently’ the same, although I think “http://” is a better URL form for your SEO linking campaign, just because that form is SHORTER than “http://www.” :razz: .

If you’re new here, you can subscribe to my blog’s full RSS feed to read the latest entries at the convenience of Google Reader or other RSS readers. Thanks for visiting!



Related posts on 

If you like "Using Mod-rewrite to Redirect Non-www URL to www URL,"
please consider linking to this page:

16 Comments to “Using Mod-rewrite to Redirect Non-www URL to www URL” »
  1. [...] Using Mod-rewrite to Redirect Non-www URL to www URL [...]

  2. July 2nd, 2009 at 8:49 pm
    sharon wrote:

    I like the script you have provided. However, it doesn’t work on the my domain with .us

    eg, ABC.us
    Please help, it shows the following:

    Redirect Loop

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.

    * Have you disabled or blocked cookies required by this site?
    * NOTE: If accepting the site’s cookies does not resolve the problem, it is likely a server configuration issue and not your computer.

    Reply to this comment »
  3. October 23rd, 2009 at 1:59 pm

    Thank for your tips, i has been looking this rewrite from non-www to www quite sometimes, i definitely will bookmark your URL

    Reply to this comment »
  4. November 16th, 2009 at 6:05 am
    JohnShep wrote:

    There is an error in the code …
    RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]

    should be

    RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]

    that is why it is looping

    Reply to this comment »
  5. February 3rd, 2010 at 6:28 am
    bert wrote:

    is there a way to simply rewrite any www domain to non-www domain without having to list the domain name each time?

    Reply to this comment »
  6. February 24th, 2010 at 3:49 am
    Dolly wrote:

    Hi,

    I have follwed the above steps to Redirecting non www URL to www URL through mod_rewrite but its giving HTTP/1.1 200 OK in Server Header Checker Tool it is not redirecting….

    Any solutions..

    Reply to this comment »
  7. August 13th, 2011 at 4:48 am
    admin wrote:

    Tips For New Bloggers,Seo Blogger templates, Seo Forum,Blogger Seo , Free Seo Tools, Free backlink

    http://www.admin-seo.blogspot.com/

    Reply to this comment »
  8. November 4th, 2011 at 4:29 pm

    thanks this .htacess method works better than the methods i was previously using…

    Reply to this comment »
  9. December 20th, 2011 at 8:58 pm
     ??SEO?? wrote:

    Just stumbled upon this article after restructuring the URLs of one of my websites. I am a little nervous as I am still seeing visitors going to old URL’s, and I did not do any 301 redirects. So I just made my 404 error a lot friendlier. The good news is my site was not generating a ton of traffic beforehand, so I am hoping I haven’t lost any ground in that respect… actually hoping to gain ground over time. Thanks for the useful tips.

    Reply to this comment »
  10. February 1st, 2012 at 2:38 am
    ummed wrote:

    i get many valuable information here related toMod-rewrite to Redirect the which is very important i like it. i am in terested indigital marketing for Digital Marketing is the new concept of marketing in the era of increasing popularity of internet marketting.

    Reply to this comment »
  11. [...] Using Mod-rewrite to Redirect Non-www URL to www URL [...]

  12. February 28th, 2013 at 5:25 am
    seo company wrote:

    An impressive share! I’ve just forwarded this onto a colleague who has been doing a little homework on this. And he actually ordered me dinner due to the fact that I stumbled upon it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending time to talk about this issue here on your web site.

    Reply to this comment »
  13. February 28th, 2013 at 6:06 pm

    Thanks , I have recently been searching for information about this
    subject for ages and yours is the best I have came upon so far.
    But, what about the bottom line? Are you sure in regards to
    the supply?

    my page; wordpress webseiten

    Reply to this comment »
  14. March 7th, 2013 at 2:24 am

    Hi there, I wish for to subscribe for this weblog to
    take newest updates, thus where can i do it
    please help.

    Here is my blog post – lenkmatte handles

    Reply to this comment »
  15. March 18th, 2013 at 6:22 pm

    Yes! Finally someone writes about remortgage in uk.

    Reply to this comment »
  16. May 7th, 2013 at 10:02 am

    What’s Taking place i am new to this, I stumbled upon this I’ve found
    It positively useful and it has helped me out loads.
    I hope to contribute & help different customers like its helped me.
    Great job.

    Reply to this comment »
Leave a Comment




(spam protection)
Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

« Previous
« Why Yahoo New Robots-Nocontent Tag Will Have Little Use | Up Top | WordPress SEO Tutorials »
Recent Comments
dog biscuits homemade: Couldn’t have put it more accurately myself
pozycjonowaniestron365.blogspot.com: What’s Taking place i am new to this, I stumbled upon this I’ve...
twitter.com: hello!,I love your writing so much! percentage we keep up a correspondence more about your post on AOL?...
click here for gay porn: I’m not sure why but this website is loading extremely slow for me. Is anyone else...
website design professional: Hi! Would you mind if I share уouг blog ωith mу myspace group?...
reverse osmosis water filter and sodium: It doesn’t price a fortune. At $98. It does the job efficiently.
Huntington Cashier: Great post. The title is the most basic and perhaps the most potent SEO item to focus on. A good...
Misspelled Ebay: Excellent beat ! I would like to apprentice while you amend your web site, how can i subscribe for a...