728x90 AdSpace

Latest News
Thursday, October 6, 2016

How to force www or non-www in htaccess

#Force www:

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

#Force non-www:

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

Now, when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess file.
Be sure to replace 'example.com' with your actual domain name.

Note: do not place both selections of code in the file as it will cause an error.
  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Item Reviewed: How to force www or non-www in htaccess Rating: 5 Reviewed By: Thiruvikraman Govindarajan