Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: SKIP with SetEnvIf |
|
Author |
|
csdude55
Joined: 22 Jan 2023 Posts: 23 Location: USA, Wilkesboro
|
Posted: Tue 21 Feb '23 22:40 Post subject: SKIP with SetEnvIf |
|
|
I have about 50 lines that would be best served with If / ElseIf / Else, but as far as I can tell there's no way to get If expressions to recognize environment variables. So I think I'm stuck using SetEnvIf.
Eg,
Code: | SetEnvIf var a foo=bar
SetEnvIf var b lorem=ipsum
SetEnvIf var c this=this |
When one of these conditions match, there's no need to check the remainder.
For the sake of speed, is there any way to tell it to skip ahead by X number of lines after it finds a match? Something like the [S] rule with mod_rewrite?
Or does that even matter in the Apache environment? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
csdude55
Joined: 22 Jan 2023 Posts: 23 Location: USA, Wilkesboro
|
Posted: Wed 22 Feb '23 20:31 Post subject: |
|
|
As far as I can tell, though, there's no way to get If expressions to recognize environment variables. I think that they process before mod_setenvif.
Code: | # this doesn't return a value for foobar:
SetEnvIf var a foo=bar
<If "-n env('foo')">
SetEnvIf ^ ^ foobar=exists
</If>
# but this does
<If "-z env('foo')">
SetEnvIf ^ ^ foobar=noexist
</If> |
|
|
Back to top |
|
covener
Joined: 23 Nov 2008 Posts: 59
|
Posted: Tue 28 Feb '23 4:28 Post subject: |
|
|
csdude55 wrote: | As far as I can tell, though, there's no way to get If expressions to recognize environment variables. I think that they process before mod_setenvif.
Code: | # this doesn't return a value for foobar:
SetEnvIf var a foo=bar
<If "-n env('foo')">
SetEnvIf ^ ^ foobar=exists
</If>
# but this does
<If "-z env('foo')">
SetEnvIf ^ ^ foobar=noexist
</If> |
|
I don't know if markup ate multiple parts of your post, but:
why do you expect the first setenvif to match
what are the ones enclosed in if supposed to be doing, specifically what's the first parameter? Did you mean to make it a no-op? The first parameter should be a special variable from the manual, an HTTP header name or environment variable that is sure to exist, like Request_URI
<If> can see the output of setenvif when setenvif is used in global/vhost scope or even in location context (which delays its setting of environment variables).
Code: | SetEnvIf Request_URI ^/$ dummy=1
<if "-z reqenv('dummy')">
Header always set dummy-was-set false
</if>
<else>
Header always set dummy-was-set true
</else>
|
Code: | $ wget -S http://localhost/ http://localhost/index.html 2>&1 |grep dummy
dummy-was-set: true
dummy-was-set: false
|
|
|
Back to top |
|
|
|
|
|
|