.htaccesshttp-redirecthttpsno-www

Redirect NON-www to www for https


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


Solution

  • 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