Friday, July 13, 2012

Redirect all users to access the site with 'www' prefix using htaccess file

We can redirect the site url to "www" prefix, whether the user is accessing the site without "www" prefix by adding rewrite url in .htaccess file in root folder.

add following lines in .htaccess file to add www prefix.

 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^yoursitename\.com$ [NC]

 RewriteRule ^(.*)$ http://www.yoursitename.com/$1 [L,R=301] 


Similarly we can remove "www" prefix from the url and redirect to without "www" by adding following lines in .htaccess file


 RewriteEngine on

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


0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Maintained by Web Themes