httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Mort <garyam...@gmail.com>
Subject Re: Is there a reason for internal_internal_redirect to rename env variables?
Date Thu, 29 May 2014 20:52:26 GMT

On 05/29/2014 04:38 PM, Eric Covener wrote:
> On Thu, May 29, 2014 at 4:34 PM, Gary Mort <garyamort@gmail.com> wrote:
>> An interesting oddity with mod_rewrite is that it is very
>> difficult[impossible?] to set environmental variables.
> In per-directory context only, right?
>

I believe so.  For my structure I have a single .htaccess file in my 
root directory.  A request to http://localhost/static/missing.png will 
be rewritten internally so instead of trying to load the non-existent 
file static/missing.png it will instead execute actions/badmedia.php

There is only a single .htaccess file in the root web directory[ie there 
is no static/.htaccess file or actions/.htaccess file].

What threw me initially was that I made the assumption that 
"per-directory" context meant that there were multiple .htaccess files, 
when in fact as far as I can tell it just means that for each file 
pattern, apache will reprocess the request with the ruleset specific to 
that context.

ie for apache processing, there are 3 sets of rules:
One for the root directory
One for the static sub-directory, which is inherited from the root
One for the actions sub-directory, which is inherited from the root

Even though the rulesets all come from the same file, internally Apache 
considers them independent and thus 'per-directory' refers to the 
internal processing?

The renaming of env variables causes a lot of confusion...searching 
around initially I saw many people banging their head into the same issue:
http://stackoverflow.com/questions/3050444/when-setting-environment-variables-in-apache-rewriterule-directives-what-causes

The only real solution seems to be to write a rewrite rule for every 
variable.
Ie if I want to potentially set an env variable called: 
OriginalMediaFile then I would also need to have

|RewriteCond  %{ENV:REDIRECT_OriginalMediaFile}  !^$
RewriteRule  .*  -  [E=OrginalMediaFile:%{ENV:REDIRECT_OriginalMediaFile}]|


Since I was setting potentially up to 20 variables, I didn't want to 
maintain that list which was why I looked into trying to get Apache to 
honor the 'END' flag before renaming the variables.   Since that didn't 
work, I figured I'd ask to see if there was a strong reason for renaming 
those variables in Apache 2.4.9 - since it's just a one line code change 
to fix it if there isn't.




Mime
View raw message