Redirect NON-www to www for https

Overnet picture Overnet · May 15, 2016 · Viewed 10.8k times · Source

I've the following redirect

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

How can I redirect non WWW https to WWW?

The htaccess is located in the public_html folder

Answer

Amit Verma picture Amit Verma · May 15, 2016

You can use the following :

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

This will redirect

to