Cybernet Web Design - Web Design & Linux Server Administration

Full Version: How to force www or non-www in htaccess
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
 
Code:
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]