How to redirect to https with www using .htaccess?

First check in your server

Redirect to https and www:

By using the .htaccess technique redirects to the https and www versions of your web pages to https://www.example.com. Add to site’s root .htaccess file:


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

Here, Checks if HTTPS is off, or if the request does not include www,
If either condition matches, the request follow the rule and it is redirected to the https://www.example.com

Redirect to https and non-www


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

Leave a Comment