Could you explain the difference between the two .htaccess redirects below?
The first redirect is the one I tend to use the most but it didn't work on a recent site (too many redirects – even though I didn't have any set up) but the second redirect worked and I'm curious.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The first RewriteCond checks the HTTPS flag set by the server (Check this link. Scroll to Server Variables).
The second RewriteCond checks an environment variable, which could be set by a prior RewriteRule (See Setenvvars for setting an environment variable).
Did you try using %{HTTPS} !=on?
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Note: Both links refer to the apache documentation. Depending on your used HTTP Server this might not work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With