How to force www or non-www in htaccess

API

Staff member
Joined
Nov 17, 2018
Messages
132
Reaction score
30
Points
28
Location
Indonesia
Offline
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]
 
Top Bottom