Kyle Jernigan

Relevance + Importance = Success.

www. vs. no-www. – Canonical URL Fixes

Posted on | March 27, 2009 | 10 Comments

EDIT: This is BY far my most popular post.  If you find this useful, please feel free to link to it or my home page.  Thank you!

So you’ve got your domain – www.site.com – and it works just fine and displays your information with either the www. prefix or without it (http://site.com vs http://www.site.com).  The kicker is you’re actually serving 2 duplicate versions of your website – and that’s bad, mmmkay?  You’re having canonicalization issues and you need to fix them.

4 characters, the “www.” prefix literally serves a new URL string and likewise a new website to a search engine bot, so having 2 versions of the same site on the web is not recommended.  Every search engine loathes duplicate content with the heat of a thousand supernovas so in order to serve only one version of your website, you need to make a few updates.  Or at least get your hosting provider to make them, if possible.

You need to 301 Redirect (permanently move) all requests to 1 URL version.

If you’re running a windows server, you’ll need to make an IIS update.

If you’re on a Linux machine, you’ll need to make an update to your .htaccess file.

For the sake my own sanity, I’m going to utilize redirecting all http://site.com traffic to http://www.site.com.

For Windows Users:

Follow every step HERE, it works perfectly. (check below for the next little bit of advice when you’re done though, so come back!)

I’d post my own steps and info, but that link has it down perfect.  Basically, you need to create an IIS reference for http://www.site.com and one for http://site.com.  Then, you set the reference for www.site.com to reference the files on your server.  Next, set the non-www. reference to 301 permenantly redirect to www.site.com as described in the seablick link – remember to add “$S$Q” to your domain.  You may need to update the Host Header to include www.site.com as well in the non-www. reference , which can be found under Properties -> HTTP Headers Tab -> Advanced button – > enter www.site.com in the appropriate field.

For Linux Users:

Your task is MUCH easier.  You simply need to create a file named – just like this – .htaccess – and upload to your home/index server space.  It must be in the exact directory location as your index page and it must be named “.htaccess” or it will not work at all.  You can create one named “htacces.txt” in Notepad, upload it, and rename accordingly.  You might need to check with your hosting provider to see if you’re allowed to make such updates as well, some people have super secure hosting providers.  You may also need check and make sure that Apache’s mod_rewrite.c turned ON.  I promise, this is still WAY easier than Windows’ version.

In your .htaccess file you simply need to put these few lines of code in, save it, and you’re done:

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

That’s it, all the code needed, copy, paste, save, done.

Like I said, the Linux lovers have it easy.  That’s all the code needed to change any and every request for http://site.com to http://www.site.com AND it will capture any and all page references as well.

Static Pages: http://site.com/contact.html will redirect just fine and dandy to http://www.site.com/contact.html

Dynamic Pages: http://site.com/index.php?method=569877 will redirect to http://www.site.com/index.php?method=569877 as well.

There, now you’ve got 1 version of your URL on the web.  The search engines will surely thank you for it and your users will too.

I promise, this by far the most popular error people have with their websites.  Canonical domains rank far better and have less errors than non.  It’s the most common suggestion on any SEO forum when someone is screaming to find out why their site has suddenly dropped in the rankings.  The answer is simple: you’re confusing the search engine as to which version of your site is ideal.

WAIT!  WAIT!  WAIT!  BUT WHAT ABOUT LINKS!!!

Word on the street is 301 redirects pass link juice/love, but I doubt they pass 100% the same way a non-redirected link does, but that’s a discussion for another post – mental note.  If you can, you should get in touch with sites that are linking to you and politely ask them to make a little update for you, particularly any big important really SEO helpful links.  If you can log in to a directory where you’re a member, take a minute and make the update.  And going forward, try to get links using one URL version.

Another EDIT: Chances are the below individual was having issues because of the $1 added to the end of several lines of code specified above.  You might try taking the 1 off, or the $ as well if you’re having issues.

Share This:
  • email
  • Twitter
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Yahoo! Buzz
  • Print

Comments

10 Responses to “www. vs. no-www. – Canonical URL Fixes”

  1. Paris Vega
    April 15th, 2009 @ 1:06 pm

    What a gold mine of information! Gee, thanks, Kyle!

  2. kjernigan
    April 15th, 2009 @ 1:10 pm

    You’re welcome. I just got tired of ALWAYS having to reference 2 different resources for these types of fixes. So I just decided to make my own.

  3. Which Home Page Do I Choose? « Kyle Jernigan
    April 17th, 2009 @ 1:49 pm

    [...] internally, or externally, to anything other than “http://www.sitename.com” – if your canonical domain is http://www.sitename.com.  If you’ve got links on your site to .com/index.html – and that [...]

  4. Dan
    May 18th, 2009 @ 2:58 pm

    Thanks for the info it really helped

  5. Paritosh
    June 23rd, 2009 @ 5:40 am

    Hi,
    The most easy explanation i have got on the internet while searching for the same !
    Thanks for such a nice post.
    Since, i am not a tech savvy person, i have a query, the codes you have mentioned above need to placed in the existing .htaccess file or do i have to delete the previous one and uploaded new one containing these lines ? And if these codes have to placed in the existing file then where should they be placed ?
    Any help would be much appreciated.
    Thank you.

  6. kjernigan
    June 23rd, 2009 @ 7:10 am

    You can post the code in the same .htaccess file you’ve created, just below any code that’s currently in there.

  7. Paritosh
    June 23rd, 2009 @ 7:17 am

    I did but i need to redirect www to no www and i guess the code give above does the opposite.
    Can you provide a way to redirect www to no www.

    Thanks

  8. kjernigan
    June 23rd, 2009 @ 8:05 am

    Sure, just swap the non-www. URL with the www. URL – here ya go:

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

  9. Paritosh
    June 23rd, 2009 @ 8:14 am

    Nah still cant redirect it to non www url.

    Here is my .htaccess file, take a look at it maybe you can help

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.techvorm.com$ [NC]
    RewriteRule ^(.*)$ http://techvorm.com/$1 [L,R=301]

  10. kjernigan
    June 23rd, 2009 @ 9:49 am

    Try this instead:

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

    Sometimes you have to keep playing with your update to get it just right. Hope this helps!

Leave a Reply





  • Kyle Jernigan

    Husband, Believer, rabid Bama fan, immune to stress, trendsetter, smart risk taker, Director of Interactive Marketing, COD MW2 sultan of pain (bravetide).

    If you don't know where you are:
    qrcode

  • Tag Cloud

    air shows alabama basketball coach alex rodriguez anthony grant apache april fools april fools day april fools joke bama basketball coach buzzstream canonicalization canonical steps canonical URL content writing content writing tips copy publishing crashing rockets digg domain canonicalization eric ward facebook global warming google government spending waste home page home page canonicalization home page seo htaccess htaccess update IIS update inbound links index page optimization jeff gordon Life link building linx myspace nofollow search engine optimization seo social media vacation web development website optimization wife