1

I need to validate that an environment variable exists and that the value is equal to "cloudflare", in case there is no deny access.

I have done multiple tests, and I have not been able to make it work. This is my test code.

  RewriteEngine on
  RewriteCond %{ENV:AH_SITE_ENVIRONMENT} prod
  RewriteCond %{ENV:HTTP_CDN_LOOP} !cloudflare [NC,OR]
  RewriteCond %{ENV:HTTP_CDN_LOOP} !^$
  RewriteRule ^(.*)$ - [F,L]

Thanks for the help

SolucionTi
  • 11
  • 1

1 Answers1

0
RewriteCond %{ENV:HTTP_CDN_LOOP} !cloudflare [NC,OR]
RewriteCond %{ENV:HTTP_CDN_LOOP} !^$

By checking that the variable does not contain "cloudflare" OR is not empty then it will always be blocked because when it does contain "cloudflare"; it's not empty! (2nd condition is successful and the rule is processed.)

The only way to check that an env var exists is to check that it contains something, since you can't differentiate between "not exists" and "empty" in .htaccess.

For example:

RewriteCond %{ENV:MY_VAR} .
RewriteCond %{ENV:MY_VAR} !=cloudflare

The first condition checks that the env var exists and contains at least 1 character. The second condition checks that the value is not exactly equal to "cloudflare". The two conditions are implicitly AND'd so both must be successful for the rule to be processed.

MrWhite
  • 11,643
  • 4
  • 25
  • 40