Tuesday, June 14, 2011

How to redirect www URLs to non-www?

In order to redirect all requests for www.yourdomain.com to yourdomain.com, you should set the appropriate rewrite rule. This can be done by adding the following lines at the beginning of the .htaccess file in your public_html folder:
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

From now on, when someone accesses http://www.yourdomain.com she/he will be redirected to http://yourdomain.com.
Using this method is safe because it should not create any redirection loops nor it should interfere with other rewrite rules.

2 comments:

  1. All posts and articles of this blog are really informative and great source for information,website hosting india

    ReplyDelete
  2. Excellent Blog. I really want to admire the quality of this post. I like the way of your presenting ideas, views and valuable content.
    web hosting company

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...