Permanent 301 redirection of non www domains to www domains

How to redirect your domain to domain with www prefixed

redirection of your domain (domain.com) name to www.domain.com is very useful and must be done. Reason for this is that when you have a non redirected domain name then search engines will see domain.com and www.domain.com as two separate websites. Hence you will lose much of the website traffic due to this.

One of the simplest solution for this is to add a .htaccess file and permanently redirect your domain name to www prefiixed domain name. Here’s how to do it step by step:

  1. Create a file with name ‘.htacess’
  2. Add the following code to it:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www.neerajkumar.name$ [NC]
    RewriteRule ^(.*)$ http://www.neerajkumar.name/$1 [L,R=301]
  3. replace the ‘www.neerajkumar.name’ with your domain name
  4. upload this file to your web servers root folder

Thats it. You are done. You can check the redirection by typing your domain name in the browser without www prefix.

Note: Above told method only works for apache web servers. For IIS servers I recommend reading http://www.xoc.net/works/tips/domain.asp

Hope this tip will help you! cheers!

Published by

Neeraj Kumar

#technologist #musician #traveller