Monday, December 12, 2011

Redirecting URL Without www to URL With www Using .htaccess File

This is collected from internet:
Today I learnt something new again about how to redirect my website if the visitors type in their browser such as this address: http://openscriptsolution.com (without prefix www.) then the browser will be automatically redirected it to the http://www.openscriptsolution.com (with prefix www.). This is very important for those of you who have the website, since you have to decide which URL that you will use for the consistency of your URL. In addition, Google loves the consistency of the URL that we used for our website. That’s what I have heard and known from Internet. So, here is the code how you can do that for your website by using .htaccess file.
  1. Open your .htaccess file that located inside your web root directory, and then add this following code into that file:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.openscriptsolution\.com [NC]
    RewriteRule ^(.*)$ http://www.openscriptsolution.com/$1 [L,R=301]
    </IfModule>
  2. Now when your visitors type http://openscriptsolution.com in their browser, then it will be automatically redirected it to the address: http://www.openscriptsolution.com.
Hopefully this will be helpful for you.

No comments: