0

I'm setting this in my vhost in Apache 2.4

SetEnvIf X-Forwarded-Proto https HTTPS=on

And in my .htaccess I add this rule :

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

but I get an infinit loop since my RewriteCond doesn't see the value of HTTPS.

I do a phpinfo(INFO_VARIABLES); and I get $_SERVER['HTTPS'] on

I had debug in my errorLog to get this RewriteCond: input='off' pattern='off' => matched As you see the RewriteCond doesn't see the value I set.

I read some doc as

The SetEnv directive runs late during request processing meaning that directives such as SetEnvIf and RewriteCond will not see the variables set with it.

or this link : http://www.onlinesmartketer.com/2010/05/27/apache-environment-variables-visibility-with-setenv-setenvif-and-rewriterule-directives/#Summary

And what I did is supposed to work.

What's wrong ? Thanks ;)

colas
  • 191
  • 7
  • Use the mod_rewrite functional. `RewriteCond %{HTTP:X-Forwarded-Proto} !^https` – Deadooshka Mar 14 '17 at 09:01
  • Unfortunately I can't change the .htaccess since it's commun to all different environment. I can't only update my vhost. – colas Mar 15 '17 at 07:03
  • Try E-flag. `RewriteCond %{HTTP:X-Forwarded-Proto} https`\n`RewriteRule ^ - [E=HTTPS:on]` – Deadooshka Mar 15 '17 at 10:08
  • I tried your command line and it doesn't work. I even just add RewriteRule ^ - [E=HTTPS:on] and with the phpinfo(INFO_VARIABLES); I don't see this variable : $_SERVER['HTTPS'] – colas Mar 17 '17 at 07:25
  • I also try this exemple : https://httpd.apache.org/docs/current/rewrite/flags.html And it doesn't work in my php I can't see the new variable. – colas Mar 17 '17 at 07:31
  • yes, in fact we get `%{ENV:HTTPS}` that is not the same as `%{HTTPS}`. Maybe due to security reasons. – Deadooshka Mar 17 '17 at 08:56

0 Answers0