title: When setting environment variables in Apache RewriteRule directives, what causes the variable name to be prefixed with "REDIRECT_"?
body: <p>I am trying to set Apache environment variables (for use in PHP) with the <code>[E=VAR:VAL]</code> flag on RewriteRule rules in an .htaccess file.</p>
  
  <p>I have already discovered the variables are accessed in PHP as server variables <code>$_SERVER</code> rather than <code>$_ENV</code> (which makes a certain amount of sense). However, my problem is for some rules the <code>[E=VAR:VAL]</code> flag works as expected and I end up with a variable <code>$_SERVER['VAR']</code> but for other rules I end with a variable <code>$_SERVER['REDIRECT_VAR']</code> or <code>$_SERVER['REDIRECT_REDIRECT_VAR']</code>, etc</p>
  
  <p>A. What causes an environment variable set in Apache using the <code>[E=VAR:VAL]</code> flag to get renamed by having "REDIRECT_" prepended to the variable name?</p>
  
  <p>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 <code>$_SERVER['VAR']</code> without having to resort to checking for variations of the variable name having one of more instances of "REDIRECT_" prepended to it?</p>
  
  <p><em>Partial solution found</em>. 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:</p>
  
  <pre><code>RewriteCond %{ENV:REDIRECT_VAR} !^$
  RewriteRule .* - [E=VAR:%{ENV:REDIRECT_VAR}]
  </code></pre>