Gadget, Free Software, Reviews

Using mod-rewrite .htaccess redirection

May 24th, 2007 · 2 Comments

Sometime using an url with WWW is more preferable instead of non-WWW url. In my opinion a short domain name (usually less than 7 letters) is better using WWW, and for the longer domain name is better without WWW.

Basically there are no big different between url with WWW and non-WWW, since both url delivers all visitors to the same website. Sometime it looks annoyed when you click an url with WWW, but it delivers you to non-WWW version. Therefore combining those url either with WWW on without WWW, will give confidence for the visitor.

For SEO reason, combining url ensures that your page won’t be double indexed by the search engines. Google bot does a pretty good job on indexing your page and it could create two distinct index for each url even though they are 100% identical in content. Obviously these duplication is not good for SEO. To change this url without your visitor ever noticed, is easy using .htaccess redirection.

You can combine these url using .htaccess 301 redirect. Just put the following code on your top of .htaccess file and it will seamlessly deliver your visitor from non-WWW url to WWW url.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

If you want to set your url from WWW to non-WWW, use the following code.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [nc]
RewriteRule (.*)$1 [R=301,L]

Related posts:

  1. Member List of Link Exchange Programs
  2. List of Free Web Directory
  3. Using WLAN Card on Ubuntu 7.04 Feisty Fawn
  4. Another Internet Explorer 7 Vulnerability
  5. Use Scribus Instead Of PageMaker

2 comments for this entry ↓

  • 1 rewrite guru // May 25, 2007 at 2:31 pm

    I prefer this code:

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

  • 2 admin // May 25, 2007 at 2:39 pm

    Thanks, for the code.

    I’ll give that try

Leave a Comment