Cybernet Web Design - Web Design & Linux Server Administration
How to force www or non-www in htaccess - Printable Version

+- Cybernet Web Design - Web Design & Linux Server Administration (https://www.cybernetwebdesign.com)
+-- Forum: Web Design (https://www.cybernetwebdesign.com/Forum-Web-Design)
+--- Forum: .htaccess (https://www.cybernetwebdesign.com/Forum-htaccess)
+--- Thread: How to force www or non-www in htaccess (/Thread-How-to-force-www-or-non-www-in-htaccess)



How to force www or non-www in htaccess - cybernetwebdesign - 09-13-2016

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]