Monday, April 22, 2013

Redirect non-www domain to www using .htaccess file

Hello friends,

Today in Developer's Blog, I am going to tell you the way to Redirect your domain from non-www to www using .htaccess file.

Suppose you have domain named www.example.com and if users browse the url by example.com and you want the www in the url, so you can write the below code to redirect to non-www to www using .htaccess file.

Here's the code you will have to write in .htaccess file : 

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

So by this you will be able to Redirect to www from non-www using .htaccess file.

I hope this will help you and you will like it.

Don't forget to leave your comments.

Thank you
Ravinder

1 comment: