Keyword Research Pro
May 15, 2009 – 2:54 pm | 5 Comments

I recently pre-launched Keyword Research Pro Version 1.0.10, which is a partnership between a young and talented programmer, Sebastian Kohl and myself.
Together, our goal is to make Keyword Research Pro the ultimate keyword software in …

Read the full story »
Affiliate Marketing

affiliate marketing strategies and tips

Google AdWords

PPC strategies for maximizing your AdWords profits

Private Label Rights

PLR strategies to skyrocket your online profits

Keyword Research

little-known keyword research strategies revealed

Teleseminar

replay of teleseminar sessions hosted by fabian lim

Home » General, Internet Marketing, Website Development

Redirecting Non-WWW Domain to WWW Using htaccess

Submitted by Fabian Lim on November 30, 2008 – 5:01 pm6 Comments

Many websites have canonical problems especially with their main domain URL.

According to Matt Cutts, Google Engineer, canonicalization is the "process of picking the best url when there are several choices, and it usually refers to home pages." 

Cutts continues to explain that "…when Google “canonicalizes” a url, we try to pick the url that seems like the best representative from that set."

So for example, the search engines consider fabianlim.name, www.fabianlim.name and  fabianlim.name/index.php to be different web pages, even though they all serve up the same content.

This results in a link popularity "split" between URLs and will affect the effectiveness of your search engine optimization efforts.

One solution to fix this problem is to perform a 301 redirect via the use of htaccess.

Two versions of the .htaccess solution exist, a generic and non-generic solution.

First, try the generic version because it does not require any modification of the code at all. 

If the generic version does not work, you can try the non-generic version.

If your website already has a .htaccess file on the server, I strongly recommend  first you create a backup version of the file on your local computer in case you mess up the codes accidentally.

So, to redirect the non-www version of your URL to the www version,  copy and paste one of the two 3-line codes below into an empty text file and name the text file as htaccess.txt:

Version 1 (Generic Version)

(More user-friendly especially if you have multiple websites since you don’t need to insert your domain URL into the code below)

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

Version 2 (Non-Generic Version)

(Be sure to change example.com to your domain name and be careful NOT to add/delete spaces or add/remove any of the symbols in the code)

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

Note: For either versions to work, Apache mod_rewite needs to be enabled by your web host

Upload this htaccess.txt file onto your web directory (typically public_html for cPanel servers).

Change the file name from htaccess.txt into .htaccess (i.e. place a dot in front of htaccess).

Test the results of this change by typing the non-www version of your domain using a web browser.

If the above steps have been implemented correctly, the non-www version will redirect to the www verion of your domain.

That’s all to it!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati

Popularity: 20% [?]

6 Comments »

  • I just to know how you have .name? Still learning guy.. ;-)

  • Thoriq says:

    I think it’s up to our choice whether we set the canonical into WWW or non-WWW. but I still see many new website particularly from newbies that they don’t set one canonical to their website. I think you should take this issue to your training Fabian.

  • Angeline says:

    What if my directory already contains a file called .htaccess?

  • Fabian Lim says:

    Hi Angeline,

    If your directory already contains the .htaccess file, you can simply place the code on top of the other codes in the .htaccess file.

    Hope this helps.

    Fabian

  • Angeline says:

    Hi Fabian,

    It doesn’t work when I add to existing code in the .htaccess file. I tried once on a WordPress site an again on a normal site but both do not work when adding to existing code.

    Is there a solution?

    Thanks and regards.

  • Fabian Lim says:

    Hi Angeline, 

    For WordPress, you do not have to use .htacess to redirect non-www to www 

    All you need to do is login to your wp-admin, then click on: 

    ‘Settings’ and check that the URL you typed in the following two areas are the www version of your domain: 

    Wordpress address (URL) 
    Blog address (URL) 

    Click ‘Save Changes’ at the bottom of the page when you are done. 

    Hope this helps. 

    Fabian

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.