httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Gruno <rum...@cord.dk>
Subject Re: [users@httpd] <If> test against env variable previously defined by SetEnvIf
Date Tue, 10 Apr 2012 15:25:26 GMT
On 10-04-2012 17:15, Pierre-Rudolf Gerlach wrote:
> Hello,
>
> I have a website hosted in a shared environment, so I only have access
> to a .htaccess file to configure stuff. I'm running on Apache 2.4.1.
>
> I would like to to something like
>  - test the user-agent against a regexp and set a variable according to this
>  - test if this variable is set and do something it it is
>
> My problem is : although the variable is set, I can't figure out how
> to test it in the <If> directive. I tried with %{ENV:myvar} and
> env('myvar') (and other stuff that threw me errors)
>
> Here's a sample .htaccess to demonstrate my problem :
>
>
> # Set a value to a variable named "myvar"
> SetEnvIf dummy .* myvar=value
>
> <If "%{ENV:myvar} == 'value'">
> SetEnvIf dummy .* myres=WIN
> </If>
> <If "env('myvar') == 'value'>
> SetEnvIf dummy .* myres2=WIN
> </If>
> <If "-z %{ENV:myvar}">
> SetEnvIf dummy .* myres3=myvarIsEmpty
> </If>
> <If "-z env('myvar')>
> SetEnvIf dummy .* myres4=myvarIsEmpty
> </If>
>
> Header set test_safari "%{myvar}e"
> Header set test_myvar "%{myres}e"
> Header set test_myvar2 "%{myres2}e"
> Header set test_myvar3 "%{myres3}e"
> Header set test_myvar4 "%{myres4}e"
>
>
> The response headers are :
>
> Server:Apache/2.4.1 (Unix)
> test_myvar:value
> test_myres:(null)
> test_myres2:(null)
> test_myres3:myvarIsEmpty
> test_myres4:myvarIsEmpty
>
>
> How would I have a "WIN" printed ?
>
>
> Thanks
>
You seem to have an error in your second If-statement (a missing quote).
I tested an If-clause on my 2.4 using the following example:

SetEnvIf dummy .* myvar=value
<If "env('myvar') == 'value'">
 Require all denied
</If>

And lo and behold, I got access denied, so it should be working as
intended, provided you fix your type :)

With regards,
Daniel.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message