How to Redirect Non – WWW TO WWW & Vice Versa

The ways to redirect the url from non-www to www and vice versa.

if its a “443” replace the code with “https” instead of “http”

[1] How to redirect www to non-www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]

[2] How to redirect non-www to www: 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]

You may also like...

Leave a Reply