setEnvIf and RewriteCond doesn't catch it

888 views Asked by At

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 ;)

0

There are 0 answers