2

While there's documentation available on Apache environmental variables, I can not find answer to one important question. Imagine I use rewrite rules to set environmental variable

RewriteRule ... ... [E=something:1]

What is the scope of "something" - global Apache server (this means "something" will be available for other request transactions), this request (means that "something" is only valid for THIS http request (and its related processing - but what's about internal redirects and other internal stuff - are they considered as THIS request, or another one?), and may be set differently within another (concurrent) request?

1 Answer 1

2

The scope is this request and can be set differently in another concurrent request. The relevant part of the docs is this:

Conditional Per-Request Settings

For additional flexibility, the directives provided by mod_setenvif allow environment variables to be set on a per-request basis, conditional on characteristics of particular requests. For example, a variable could be set only when a specific browser (User-Agent) is making a request, or only when a specific Referer [sic] header is found. Even more flexibility is available through the mod_rewrite's RewriteRule which uses the [E=...] option to set environment variables.

source

6
  • 2
    It says "ALLOW ... TO BE SET", but does not clearly state that if I set env var it will be specific to request. If I am allowed to do something, it does not mean I will get behavior I need. It should be "the directives provided by mod_setenvif SET environment variables on a per-request basis, conditional on characteristics of particular request". Then it is clear.
    – Anonymous
    Jun 7, 2014 at 15:17
  • 1
    Did you skip the title? It clearly says Conditional Per-Request Settings, meaning that if you set them using Setenv_if or the flag E in mod_rewrite, these are set per-request.
    – mvillar
    Jun 7, 2014 at 15:21
  • If its name would be "per-request setting", it would be more clear than it is with "conditional" word. Also, let's look at this statement: "For example, a variable could be set only when a specific browser (User-Agent) is making a request, or only when a specific Referer [sic] header is found". Literally it means if there're several sessions with same User-Agent (e.g. desktop) they will get SAME environment variable in SAME state. Also, if there're two sessions from same referral, these sessions will also receive same variable, even if they are expected to be different (eg.depending on cookie)
    – Anonymous
    Jun 7, 2014 at 19:35
  • Yes, the same environment variable would have the same state, but that variable would be set on a per-request basis: A request arrives, we look at it's user-agent and set the environment variable. When other request arrives, for that request, the variable is unset until we look at its user-agent and (in that precise moment ) we set it to the same value than before.
    – mvillar
    Jun 7, 2014 at 20:30
  • Who - "we"? You mean some custom code in httpd.conf or .htaccess (speaking about "examples" in the original Apache manual page)? It should be clearly and explicitly explained on that page. The logic how it works/explained is not clear. These examples should be backed up by the code.
    – Anonymous
    Jun 7, 2014 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .