How to escape spaces in Apache SetEnvIf value

In the end I figured it out for myself…

SetEnvIf Request_URI "^/example" "AUTH_KEY=a b"

… which looks odd, but works. It correctly sets AUTH_KEY to value a b

Hopefully this might save someone else's time in the future.

The details:- I am not a C programmer, but bumbling around on Google I found mod_setenvif.c listed at http://www.bvbcode.com/code/s6148jvr-385031

A function is called on line 405 (ap_getword_conf, for which I found detail at http://docstore.mik.ua/orelly/apache_mod/155.htm) which seems to parse strings, delimited by whitespace (but optionally encapsulated in quotes and accepting the use of escape characters).

I noticed that this happened before the sub-string returned by the function above being split by the '=' character (line 411, by function ap_getword). Thus quotes around the key=value pair, rather than just the value.


Try using instead SetEnvIf Request_URI "^/example" AUTH_KEY="a\sb". \s here represents the space.