Matt's Blog

Matt’s Blog Gets No-WWW.org Class B Compliance

June 24th, 2007 at 4:48 PM (17 years ago) by Matt Freedman

I have just made it so that all traffic going to www.mattsblog.ca will be silently redirected to mattsblog.ca. Which makes Matt’s Blog a Class B (the preferred class) in No-WWW.org‘s books.

If you’ve never heard of no-www.org before, it’s basically a campaign trying to raise the fact that www. is/should be deprecated. They have 3 “ranks” or “classes”. Class A, B and C.

Class A All traffic to www.domain.com and domain.com is accepted, and no redirect happens.
Class B The preferred class. All traffic to www.domain.com is silently redirected (301) to domain.com.
Class C The hardcore class. Traffic to www.domain.com is denied and the user can only access the site through domain.com. This class is not recommended.

Most hosts default their DNS to Class A. Where all traffic to www.domain.com and domain.com is accepted. The problem with Class A is that Search Engines might penalize you for having duplicate content (because you have the same content on www.domain.com and domain.com) and you might end up with Search Results with and without the “www.“. You could even have 2 different PageRanks for your main page, depending on if you check with www. or no-www. Google allows you to define which domain you would like to show up in their Search Results. You can do this through Google Webmaster Tools. But, Google is only 1 of the many Search Engines.

So, how can you redirect www.domain.com to domain.com. Well, it’s actually quite simple. This way will only work on Apache servers with mod_rewrite enabled. First, create a file (or open it, if it already exists) in your site’s root called .htaccess (including the period, but nothing before the period). Then, place this code in it (replace domain\.com with your domain name, make sure you escape the period):

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

Let’s go over that code now.

RewriteEngine On simply tells Apache to allow you to use the mod_rewrite module (make sure it’s installed, first).

RewriteBase / makes sure we’re working on the root domain.

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] tells the Server to see if the URI requested has the domain www.domain.com. The [NC] tells it that it’s case-insensitive.

RewriteRule ^(.*)$ http://domain\.com/$1 [R=301,L] says that if RewriteCond is true to silently redirect the user to domain.com. ^(.*)$ holds the value of what was after the original URI. $1 then makes sure that they’ll be redirected to the same page they requested. [R=301,L] will tell the User-Agent (browser, or bot) that the redirect type is 301 Permanent and and L tells the Server that it’s the last rule.

Note: If you’re using WordPress for the site in question, the above code must go above WordPress’ redirect stuff. So place it somewhere above # BEGIN WordPress.

Then, save the file and upload it to your site’s root. Now, all that’s left to do is to get Validated by no-www.org. Go here to do that. Your site should now be a Class B!

That’s it, your site is now even more Search Engine friendly.

Get it? Got it? Good!

One Response to “Matt’s Blog Gets No-WWW.org Class B Compliance”

  1. Matt’s Blog » Blog Archive » WordPress 2.3
    Matt’s Blog » Blog Archive » WordPress 2.3 says:

    […] There’s been some cool changes to the Permalink system, go can see the changes in the this comment on the Trac ticket. Including enforcing either www. or no www. […]

Leave a Reply

Quote selected text

Leave the following field empty: