httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre-Rudolf Gerlach <>
Subject [users@httpd] <If> test against env variable previously defined by SetEnvIf
Date Tue, 10 Apr 2012 15:15:45 GMT

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 "env('myvar') == 'value'>
SetEnvIf dummy .* myres2=WIN
<If "-z %{ENV:myvar}">
SetEnvIf dummy .* myres3=myvarIsEmpty
<If "-z env('myvar')>
SetEnvIf dummy .* myres4=myvarIsEmpty

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)

How would I have a "WIN" printed ?


Pierre-Rudolf Gerlach

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message