I am trying to set Apache environment variables (for use in PHP) with the [E=VAR:VAL] flag on RewriteRule rules in an .htaccess file.
I have already discovered the variables are accessed in PHP as server variables $_SERVER rather than $_ENV (which makes a certain amount of sense). However, my problem is for some rules the [E=VAR:VAL] flag works as expected and I end up with a variable $_SERVER['VAR'] but for other rules I end with a variable $_SERVER['REDIRECT_VAR'] or $_SERVER['REDIRECT_REDIRECT_VAR'], etc
A. What causes an Environment Variable set in Apache using the [E=VAR:VAL] flag to get renamed by having "REDIRECT_" appended to the front of the variable name?
B. What can I do to make sure I end up with an Environment Variable with an unchanged name so I can access it in PHP as $SERVER['VAR'] without having to resort to checking for variations of the variable name having one of more instances of "REDIRECT" appended to the front of it?
Partial solution found. Adding the following to the start of the rewrite rules recreates the original ENV:VAR on each redirect (as well as leaving the REDIRECT_VAR versions there) if they're needed:
RewriteCond %{ENV:REDIRECT_VAR} !^$
RewriteRule .* - [E=VAR:%{ENV:REDIRECT_VAR}]