Hello, everyone. Today I'll show you how to force visitors to open www.example.com or example.com when visiting your website using .htaccess file.
 
 
To Remove the WWW please add the following code into your .htaccess

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

 
 
To FORCE the WWW

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