Redirecting your domain.com to www.domain.com

April 19th, 2010

With people taking steps to make their website search engine friendly, there are some basic things which can be done to get on the better side of Google. Redirecting non www domains to www domains avoids the issue of duplicate content being indexed on search engines.

Below is the code which you need to put in your .htaccess which will redirect any user who types in yourdomain.com to www.yourdomain.com

RewriteEngine on

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

Please change example.com to your website url.

Comments

  1. Siraj August 16th, 2010

    Hi,

    Can this be done on wordpress Blog as well?

    What is the benefit of doing it?

    :)

    SiRU

  2. Prashant August 16th, 2010

    Yes, this is automatically done by WP when your specify your URL in Settings. The benefit of doing this is that it eliminates the chances of duplicate content issue with search engines.

  3. Making your PHP code work within files with extension .html December 1st, 2010

    […] Related Articles: 1. Redirecting your non www domain.com to http://www.domain.com using .htaccess […]

  4. enter now December 7th, 2013

    Superb, what a website it is! This web site provides valuable data to us, keep it up.

Leave A Comment