Apache SetEnvIf failing to match Request_Uri

.htaccessapache-2.2

Simple condition, which never match and set variable:

SetEnvIf Request_URI "^/path/to/something*" access_granted

Checking URI by using PHP is giving correct string, however variable is never set.

echo getenv('Request_URI'); --> /path/to/something
echo getenv('access_granted'); --> <<empty>>

Simple as that, but still and always failing to match.

Update: interesting point is, that I can achieve access_granted=1 by string:

SetEnvIf Request_URI "^/path/*" access_granted

/path is also RewriteBase – maybe it's connected somehow, I don't know

Best Answer

The issue you are facing is maybe caused by mod_rewrite as explained under. Rewrite rules are applied before applying setenv, so that the rewritten request uri is passed to it. Try to set the env variable on rewrite.

Related Topic