httpd-users mailing list archives

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

-- 
Pierre-Rudolf Gerlach

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


Mime
View raw message