I have problem with http to https redirection using .htaccess
I use this code on .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have tested and used before on other servers, and it worked fine
But here on this server it fails, when I try to visit this site (http or https) I doesn't work, it returns following error message:
ERR_TOO_MANY_REDIRECTS
so.. I begin to test and try different things trying to understand what was happening.. and finally I found problem (but still did not find solution)
problem is that for some reason %{HTTPS} match to "off" if I use http it matches to off (correct) and if I use https:// it matches to "off" (and that is wrong! it should match to "on".
To be sure that it was the problem I replaced .htaccess content with following
RewriteEngine On
RewriteRule ^aaa.html$ https://%{HTTP_HOST}/foo.html?%{HTTPS} [R=301,L]
I did that to see value assumed by %{HTTPS}
And when I visit https://www.example.com/aaa.html I am redirected to
https://www.example.com/foo.hml?off when it should go to
https://www.example.com/foo.hml?on
why %{HTTPS} is off when I visit it using https?
%{SERVER_POST}
instead?