www vs non-www (301 redirect)

October 28th, 2006

301 redirectMost sites are accessible through either http://website.com as well as http://www.website.com. If anyone gave you a URL without the www would you assume that the same domain with a www would take you do a different site? Of course not. However, search engines are not always that smart. They may see http://fromthefrontend.co.uk and http://www.fromthefrontend.co.uk as two different sites.

Why is this a problem? Well it could have a negative effect on your search engine ranking. The “two sites” maybe viewed as a duplicate entry or you may have in cases promoted a www version and in others a non-www version without noticing and thus your efforts are diluted.

The solution?

Redirect traffic from your non-www to your www url (or visa versa). There are many ways to redirect a page - meta refresh, an info page advising to go to the correct url etc. But in this case your best option is the 301 redirect.

There are 2 main reasons
1) It is search engine friendly and will preserve your exisiting ranking
2) Most webhosts do not enable you to direct traffic for www and non-www to different destinations so you couldn’t put an info page or metta refresh in place to redirect the traffic
3) Using the wrong method can get you BANNED from google as Business.com discovered. Check out the full story on webpro

Fortunately the 301 redirect is easy enough to implement. You will need to be able to use .htaccess files (i.e using a Linux server running Apache and the Mod-Rewrite moduled enabled).


Create a .htaccess file containing the following:

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

Put this in the Root of the site you wish to apply this to. Remember to change “yoursite.com” for your real domain.
WARNING: if your site already contains a .htaccess file then add this code to the bottom of that file (new paragraph).

I’ve used this technique on this blog. Try going to http://fromthefrontend.co.uk and see what actually appears in the address bar.

When you have set this up on your own domain check it working and is search engine friendly on the Search Engine Friendly Redirect Checker

If you found this tutorial useful and have implemented it please post your URL here so we can check it out. Any feedback on difficulties you may have had would also be useful.

If you want to see what else you can do with 301 redirects check out the webconfs seo toolset

Please note: I have not tried all of the 301 methods listed on webconfs and the .htaccess option they have listed did not work for me (needed slight amendment) so please test for yourselves.

Have your say?

Comments welcome - you don't have to agree :)

2 Responses to “www vs non-www (301 redirect)”

  1. fc on November 13, 2006 2:51 pm

    if you put in fromthefrontend.co.uk/2006/10/28/www-vs-non-www-301-redirect/, it doesn’t send you to the right page.

  2. David Long on November 13, 2006 11:30 pm

    I’ve set up my redirect so that any bad urls or urls without the www will go to my home page. I’ll have to research how to redirect simply add-in “www” to urls rather than redirect them to the homepage for a future article.

Name (required)

Email (required)

Website


Speak your mind

Trackback URL | Comments RSS

    About

    Although originally designed to document my work and new web development tricks I learnt it has expanded to cover tech and news that I find interesting so in addition to tutorials and interviews expect to see product reviews and tech news too. If you enjoy please comment. David

    Blogroll
    • Adele Kirby - Freelance Writer and most chipper/perky person alive
    • Alex Pullin - Freelance Tech Writer and former PR queen
    • Display: Block - Blog of fellow developer Savell Martin
    • Molly E. Holzschlag - Web standards advocate and Genious
    • Nate Laxon - Funny guy and music guru
    • Paul Boag - Helping website owners and promoting webstandards. The King of Web Design Podcasts
    • Poached Online - news/current affairs/political comment: no eggs
    • Tale of 2 Blogs - Blog about my other blogs
    Admin
  • From Display:Block
    • SpringWidgets
      RSS Reader
      This widget is the staple of our platform. Read all your feeds right here with this one widget - Supported feeds are OPML, RSS, RDF, ATOM. Watch your favorite Podcast in the embedded Video Player on the Desktop or publish your own video playlist to your site for others to view!
      Visit the Widget Gallery