June 14, 2005

Cleaning Up Canonical URLs With Redirects

What the heck is a canonical URL? I didn’t know what a canonical URL was at first either, so don’t worry if you don’t know.

Canonical essentially means “standard” or “authoritative”, so a canonical URL for search engine marketing purposes is the URL you want people to see. Depending on how your web site was programmed or how your tracking URLs are setup for marketing campaign, there may be more than one URL for a particular web page.

The problem most search engine marketers run into deals with domains. Sometimes if a domain is not setup properly, the domain URL (domain.com) and the www domain URL (www.domain.com) are considered individual web pages. Since both pages maybe indexed by Google - you could get hit for duplicate content and at the very least you would be splitting your link popularity.

The easiest way to protect your site is to redirect all forms of your domain to one “standard” URL - a canonical URL.

For example to force the use of www.socialpatterns.com instead of socialpatterns.com, I have these lines in my .htaccess file. (This is Apache specific, if you use IIS the lines should be the same using ISAPI filter)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^socialpatterns\.com$ [NC]
RewriteRule ^(.*)$ http://www.socialpatterns.com/$1 [R=301,L]

The first line “RewriteEngine On” tells Apache to enable Mod_rewrite - the engine responsible for manipulating URLs.

The second line “RewriteCond %{HTTP_HOST} ^socialpatterns\.com$ [NC]” looks for when people access socialpatterns.com. The “[NC]” flag makes the test case-insensitive, so it catches URLs like SoCiAlPatTerns.com.

The third line “RewriteRule ^(.*)$ http://www.socialpatterns.com/$1 [R=301,L]” redirects socialpatterns.com to www.socialpatterns.com with a 301 redirect.

Michael Nguyen | Search Engine Marketing, Technology | Comments (31)

31 Responses to “Cleaning Up Canonical URLs With Redirects”

  1. Hunter S Says:

    So if someone else buys your domain without the www, then they can really jack your link popularity and probably get you banned eventually. Right?

    If so everyone would need to run out and buy that version of their domain and use 301 redirect on it immediately!

  2. Michael Nguyen Says:

    Hunter:
    The domain with the www and without are the same domain. Remember that when you purchase a domain you have full access/control of the subdomains. No one can buy a seperate subdomain of your own domain.

  3. Chris Blood Says:

    Hey, thanks for the tip! I just implemented it and it worked perfectly :)

    I love this site. Good good stuff.

  4. Paul Says:

    Awesome tip — thanks! :)

  5. Tim Says:

    Sorry for maybe asking a dumb question, but what would be the same varient for the .htaccess for my .asp hosted sites? Thanks

  6. Tim Says:

    What do you mean by “should be the same using ISAPI filter” I have some Windows hosting that I would like to use this .htaccess file idea with
    Please advise (2nd request)

  7. Travis Says:

    Why not just set your DNS A records so that http://www.website.com and website.com go to the same website.

    Seems a little easier and less code to deal with.

  8. unhappy Says:

    Does anyone monitor this comments/posts????

  9. Michael Nguyen Says:

    Travis,

    The problem lies in how Google views each of these urls. Even though DNS typically points the two urls to the same website, Google will consider the two urls as seperate sites without a 301.

    Tim,
    ISAPI Filter is a mod_rewrite type program you can add onto IIS. If you are using apache, then the rules would be the same - just change the domain to your website.

  10. Michael Nguyen Says:

    Unhappy,
    Yes.

  11. Search Engine Journal » MSN’s Google PageRank of 2 and Canonical URL Problems Says:

    [...] MSN’s homepage - http://www.msn.com is now showing a Google toolbar PageRank of 2. This is another example of the canonical problem I covered in an earlier post. [...]

  12. Tim Says:

    Michael
    Is there anyway to just upload an .htaccess file onto your windows hosted domain that will give you the same results as listed above?

    Thanks

  13. Rob Lewis Says:

    Would the above example wipe out any subdomains that you might be using?

  14. » A Summary of 301 Redirect Knowledge - Stuntdubl - SEO Consultant Says:

    [...] Cleaning up canonical redirects [...]

  15. TbN Says:

    Hello, I put the code in my .htaccess file (editing the url, obviously) and when I try to enter to my site it shows an “500 error”.

    What is happening?

  16. Hagrin Says:

    Thank you SOOOOOOOOOO much for the tip. This resolved my problem IMMEDIATELY and will prevent improper search engine crawling. Thank you!!!!

  17. Will Says:

    Finally a solution that works for me. :)

    Thanks a lot,

    Will

  18. W Says:

    Nothing I try seems to accomplish the renaming. The old name I am having trouble with is permanently forwarded by the old ISP to the new address but for some reason it locks the old name into place.

    The old site la-ldr.site.org needs to become community.site.org

    How does google etc treat these subdomains of the main site.org?

  19. Vince Says:

    I thinks it’s about time Google resolved this issue on their side of things, not ask all millions of Website owners to change what has been ‘the norm’ since the begining of the internet.

  20. Goldbar Cart Says:

    What about http://www.goldbar.net, http://www.goldbar.net/index.html , what should I do with it?

  21. Michael Nguyen Says:

    Goldbar,

    Point everything to one url or the other. I recommend sticking with the http://www.goldbar.net url.

  22. ATIQ UR REHMAN Says:

    I tried to redirect urls of my website http://www.goldbar.net using 301 and everone of them has been giving me an
    error saying that I get the following error message “Redirection limit for
    this URL exceeded. Unable to load the requested page. This may be caused
    by cookies that are blocked”.
    Any ideas?

  23. SEO delusions » Another lesson in SEO: Site Availability Says:

    [...] There is a humorous post over on Digg from SEOmoz. They were trying to do the right thing and help Kevin Rose save a few bucks by getting them to adopt of the practice of using 1 single domain name, without variation. See here, here and here for examples. Anyway in doing so they apparently (I’m just guessing) drove so much traffic to their own site that their servers have crashed. I thought this was a perfect segway into another SEO mishap that can plague companies and that is web site availability. Simply put, if you happen to work for a company or organization that has spent the money on the content, spent the money on SEO but haven’t spent the cash to keep the servers up you are shooting yourself in the foot. It isn’t even about keeping the server up, if your server doesn’t respond quickly enough to the search engine spiders it will literally start to back away from your site in fear of causing a problem. This results in less pages getting indexed and on a less than regular basis. Which as we all know leads to less of your pages showing up in search results and less organic traffic. [...]

  24. Matt Cutts: Gadgets, Google, and SEO » Canonicalization update Says:

    [...] For the people who want to make sure that all their webmaster ducks are in a row on this topic, here’s my two-minute advice: - Pick one way of writing all your urls and use that consistently in your pages and your links. - If you pick (say) http://www.example.com as your preferred root page, make sure that you have a permanent (301) redirect from pages such as example.com to http://www.example.com. Michael Nguyen has a nice short post about how to do this in Apache, or Beyond Ink shows how to do a 301 redirect on several platforms. - To be extra safe, feel free to use Google’s webmaster console to specify the preferred root page of your domain (www.example.com vs. example.com). Read this post by Vanessa for more details. [...]

  25. Carl Hudson Says:

    My question is (not knowing much about apache) is it a simple matter of swapping the two URL parts if domain.com is your preference to direct to?

  26. Canonicalization update - rankoz.com Says:

    [...] For the people who want to make sure that all their webmaster ducks are in a row on this topic, here’s my two-minute advice: - Pick one way of writing all your urls and use that consistently in your pages and your links. - If you pick (say) http://www.example.com as your preferred root page, make sure that you have a permanent (301) redirect from pages such as example.com to http://www.example.com. Michael Nguyen has a nice short post about how to do this in Apache, or Beyond Ink shows how to do a 301 redirect on several platforms. - To be extra safe, feel free to use Google’s webmaster console to specify the preferred root page of your domain (www.example.com vs. example.com). Read this post by Vanessa for more details. [...]

  27. Josh Says:

    great info, thanks!
    But I need to extend this a bit and not sure how exactly to do it.
    I have 2 domains, domain.com and domain.org, that point to the same site.
    How do I redirect http://domain.org, http://www.domain.org and http://domain.com to http://www.domain.com

  28. Canonicalization update · djanggo.com Says:

    [...] For the people who want to make sure that all their webmaster ducks are in a row on this topic, here’s my two-minute advice: - Pick one way of writing all your urls and use that consistently in your pages and your links. - If you pick (say) http://www.example.com as your preferred root page, make sure that you have a permanent (301) redirect from pages such as example.com to http://www.example.com. Michael Nguyen has a nice short post about how to do this in Apache, or Beyond Ink shows how to do a 301 redirect on several platforms. - To be extra safe, feel free to use Google’s webmaster console to specify the preferred root page of your domain (www.example.com vs. example.com). Read this post by Vanessa for more details. [...]

  29. Ginxy33 Says:

    I have a domain and a sub-domain, both with the same content. The original domain “example.com” was a static site and we needed to add a shopping cart. I used a sub-domain “example.example.com” to build the shopping cart site and test it out. Once completed, I did a redirect on the “example.com” site to point to the “example.example.com” site.

    I am now using the original site “example.com” for testing, of course I still have the redirect. Would this be considered duplicate?

  30. einfach persoenlich Weblog Says:

    Google Pagerank – Alles neu macht der Mai?…

    Frühjahrsputz steht an, auch im Hause Google. Doch statt des erwarteten PR-Zuschlages kommen hagelt es scheinbar mehr PageRank-Abfall bei den Domains. Wenn Google aufräumt, ist Freund und Leid nah beieinander. Seit Jahren nun ist der kleine g…

  31. Larr @ VoltRider Electric Bicycle Says:

    Hi all…

    Relative newbie here learning about all this after just create a web site for my new business venture. I just published my site and Google searches just began displaying some of the pages last night. As I was exploring Webmaster Tools yesterday I discovered in the Settings tab the option to choose a preferred URL or not.

    Have to admit this is a bit overwhelming for a beginner but I was wondering if someone could elaborate a bit more on how to check (and what to look for) with regard to “internal links”. I assume you’re referring to the links on each web page that link to all the other pages on your site? So what is it that we’re supposed to look for?

Leave a Reply