logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: SKIP with SetEnvIf
Author
csdude55



Joined: 22 Jan 2023
Posts: 23
Location: USA, Wilkesboro

PostPosted: Tue 21 Feb '23 22:40    Post subject: SKIP with SetEnvIf Reply with quote

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

PostPosted: Wed 22 Feb '23 11:02    Post subject: Reply with quote

Apache has if[1] and elseif[2] and else[3]

See also https://stackoverflow.com/questions/42137409/apache-2-4-nested-if-directives

[1] https://httpd.apache.org/docs/2.4/mod/core.html#if
[2] https://httpd.apache.org/docs/2.4/mod/core.html#elseif
[3] https://httpd.apache.org/docs/2.4/mod/core.html#else
Back to top
csdude55



Joined: 22 Jan 2023
Posts: 23
Location: USA, Wilkesboro

PostPosted: Wed 22 Feb '23 20:31    Post subject: Reply with quote

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

PostPosted: Tue 28 Feb '23 4:28    Post subject: Reply with quote

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


Reply to topic   Topic: SKIP with SetEnvIf View previous topic :: View next topic
Post new topic   Forum Index -> Apache