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

Did you know the URLs “www.The SEO” and “http://The SEO” 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 (same as www.The SEO
* The SEO (same as http://The SEO
* www.The SEO
* The SEO

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” 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 “” and the other half to “” 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: to

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” to “http://The SEO“:

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

*Note: you should change “The SEO” 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 “” 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 “” instead of “”

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

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:

43 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

    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:


    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

    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 »
  17. If you desire to get much from this post then you have to apply these strategies to your won blog.

    Reply to this comment »
  18. June 7th, 2013 at 5:04 pm

    Wow, this piece of writing is nice, my sister is analyzing such things, therefore I am
    going to let know her.

    Reply to this comment »
  19. July 1st, 2013 at 5:31 am
    seo services wrote:

    com can be better explained as a new generation SEO Company in India that delivers
    100% ethical SEO services using the fresh web marketing approach
    that works in the current search engine industry.
    What began with in-your-face aggression, ruthless email spam, page upon page
    of flashing banners begging for clicks and outright deception has turned into something more targeted,
    less scattershot and more subtle. To gain a worldwide clientele base, SEO services India has had to venture out of the traditional conventions of outsourcing dens in India.

    Reply to this comment »
  20. July 1st, 2013 at 8:50 am

    Wow, awesome blog layout! How long have you been blogging for?

    you made blogging look easy. The overall look of your site is wonderful, as well as the content!

    Reply to this comment »
  21. July 1st, 2013 at 2:08 pm

    Hey! This post could not be written any better!

    Reading this post reminds me of my good old room mate!

    He always kept chatting about this. I will forward this page to him.

    Pretty sure he will have a good read. Thank you for sharing!

    Reply to this comment »
  22. July 16th, 2013 at 3:38 pm
    kredyty wrote:

    I savour, cause I discovered just what I was taking a look for.

    You’ve ended my 4 day lengthy hunt! God Bless you man. Have a nice day. Bye

    Reply to this comment »
  23. July 17th, 2013 at 2:47 am
    loan wrote:

    Thanks for some other informative website.
    The place else could I get that kind of info written in such an ideal manner?
    I’ve a mission that I am just now working on, and I have been at the glance out for such info.

    Reply to this comment »
  24. I have an excited analytical eyesight pertaining to fine detail and can anticipate issues just before these people happen.

    Reply to this comment »
  25. July 23rd, 2013 at 9:34 am

    I relish, result in I found exactly what I used to be having a look for.

    You have ended my four day lengthy hunt! God Bless you man.
    Have a nice day. Bye

    Reply to this comment »
  26. July 25th, 2013 at 1:07 am

    In order to track your backlinks, you need to
    be getting them. Rather than taking the time to write posts
    or to pay a freelance writer to ghostwrite the posts
    for them, autobloggers use a variety of methods to pull content for their
    blogs, utilizing the scheduling feature of Word – Press to schedule the posts and have them post automatically at
    predetermined intervals. Are you starting to see
    the Power behind writing your own articles. Typically, depending on the article directory,
    you can have 1-2 “non-self-serving” links in the article body
    and 2 “self-serving” links in the author resource box.

    Reply to this comment »
  27. Hey! I just want to give a huge thumbs up for the good information you will have here on
    this post. I can be coming back to your blog for more

    Reply to this comment »
  28. August 1st, 2013 at 3:36 am
    Tracie wrote:

    What’s up Dear, are you genuinely visiting this web page regularly, if so then you will definitely obtain good experience.

    Reply to this comment »
  29. August 1st, 2013 at 12:39 pm

    Hi, I do think this is an excellent blog. I stumbledupon it ;) I will revisit once again since I bookmarked it.
    Money and freedom is the greatest way to change,
    may you be rich and continue to guide other people.

    Reply to this comment »
  30. August 9th, 2013 at 4:57 am

    Hey there just wanted to give you a brief heads
    up and let you know a few of the images aren’t loading properly. I’m not sure
    why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.

    Reply to this comment »
  31. August 26th, 2013 at 1:30 pm

    Its like you read my mind! You appear to understand so much about this, such as you wrote
    the guide in it or something. I think that you
    simply could do with a few percent to drive the message house a little
    bit, but other than that, that is wonderful blog.
    A great read. I will certainly be back.

    Reply to this comment »
  32. September 20th, 2013 at 6:32 am
    Stevie wrote:

    I was curious if you ever thought of changing the layout oof your website?
    Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful llot off text for only having one or 2 pictures.
    Maybe you could space it out better?

    Also visit my blog – search engne ootimization (Stevie)

    Reply to this comment »
  33. October 23rd, 2013 at 2:11 pm
    internet wrote:

    Your style is really unique compared to other people I’ve read stuff
    from. Thanks for posting when you have the opportunity, Guess I’ll just book
    mark this page.

    Reply to this comment »
  34. November 25th, 2013 at 5:19 am

    T?i lu?n lu?n li?n t_c _? d?nh m_t n_a c_a t?i m_t gi_ __ __c
    n?y trang web ’s b?i vi_t ho_c _?nh gi?
    h?ng ng?y c?ng v_i m_t c_c c? ph

    Reply to this comment »
  35. December 4th, 2013 at 3:50 am

    I love looking through a post that will make men and women think.
    Also, many thanks for allowing for me to comment!

    Reply to this comment »
  36. December 7th, 2013 at 8:27 pm
    Kenny wrote:

    Thank you for the good writeup. It in fact used to be a enjoyment account it.

    Glance complex to more brought agreeable from you!
    By the way, how can we communicate?

    Feel free to surf to my site anatomy and physiology
    notes (Kenny)

    Reply to this comment »
  37. December 23rd, 2013 at 7:02 am wrote:

    whoah this weblog is great i like studying your articles. Stay up the good work!
    You realize, many people are hunting round for this information, you could aid them greatly.

    my web site; search engine optimization;,

    Reply to this comment »
  38. January 9th, 2014 at 12:31 am
    atdhe wrote:

    Great information. Lucky me I recently found your blog by accident (stumbleupon).
    I have saved it for later!

    Reply to this comment »
  39. January 12th, 2014 at 6:07 pm

    oakley sunglasses cheap real…

    Glitter Leather Handbag (locate link adhering to the write-up) will come in a glossy black color. It has a brown colored straps whichgives agood contrast forthe black colour. This bag is made up of Patent Leather-based containing two entrance pockets….

  40. January 21st, 2014 at 5:04 pm

    hot pink suede heels…

    Antigua was outstanding, but even far better was getting the correct to become out in public with our daughter. :-D Just after we received again to Guatemala Metropolis, I had to pack. I worked until late and certainly had difficulty fitting anything i…

  41. February 23rd, 2014 at 2:49 pm
    ppc miami wrote:

    There’s definately a great deal to know about this subject.
    I lovce all of the points youu made.

    Reply to this comment »
  42. April 7th, 2014 at 3:02 am

    This uncontrolled disposal of raw sewage into Pittsburgh’s rivers did not stop until 1958 when the Allegheny Sanitary Authority opened up it’s sewage treatment plant.
    If you reside in a plane that is prone to these types of natural disasters, you should reach out
    immediately for the inclusion of this additional protection.

    If the hair must be untangled while wet, a wide-toothed comb should be used to minimize the stretching and breaking that a brush can do to wet hair.

    Reply to this comment »
  43. April 15th, 2014 at 2:31 am

    You really make it appear so easy together with your presentation however I to find this topic to be really one thing that
    I believe I’d by no means understand. It sort
    of feels too complicated and extremely extensive for me.
    I am taking a look ahead on your subsequent put up, I will try to get
    the hold of it!

    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 There іѕ a гіgҺ 16;...
Senaida: While ѕome օf tҺеѕ 077; SΕΟ...
25 mins: I do not even know how I stopped up right here, but I thought this post was good. I don’t realize who...
lvwmhyzw30: michael kors handbags outletFriday’s attack all over the Kandahar killed a minimum of one person...
Michaelzips: michael kors watches outletPatricia Drain, author to do with Sell the Sizzle, had the opportunity...
qpdwgpkn47: nike free run australiaAs a number of us have the desired effect by the use of going to be the challenges...
Big fish for Android: s Spoken Word and her website offers products to help Christians use Bible scriptures in every...
best teeth whitening kits: Hey There. I found your blog using msn. This is a very well written article. I will make...