Redirect WWW to non-www
For HTTPS sites
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule (.*) https://example.com/$1 [L,R=301] </IfModule>
For HTTP sites
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] </IfModule>
Redirect non-www to WWW
For HTTPS sites
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule (.*) https://www.%1/$1 [R=301,L] </IfModule>
For HTTP sites
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] </IfModule>
0 Comments