Why does the 301st redirect from HTTP to HTTPS not work?

In .htaccess registered redirect:

RewriteEngine On
RewriteCond %{HTTPS} =of
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

However, when accessing the site via http, there is no redirect to https.

What else could be the reason? enter a description of the image here

Author: gubin, 2019-03-19

1 answers

Try this way:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Or so:

RewriteEngine On 
RewriteCond %{ENV:HTTPS} !on 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 1
Author: Alexander Semikashev, 2019-03-19 09:24:47