Redirect Non WWW to WWW Using .htaccess

Redirect non www to www using your domain name

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/\ [R=301,L] 

Or use this for any domain:

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

If you have ssl enabled then add this two line for http to https redirect

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Comments

comments