Apache 2.4: Set user dependent environment variable

apache-2.4environment-variableshttp-basic-authentication

I just wondered if it's possible to set an environment variable depending on the basic authentication user. I tried the following versions, but none of them work (obviously none of them is documented either):

SetEnvIf HTTP_USER   "marco" MYENV=foobar
SetEnvIf USER        "marco" MYENV=foobar
SetEnvIf REMOTE_USER "marco" MYENV=foobar

Cheers,
Marco

Best Answer

SetEnvIf is used to set environment variables based on attributes or header of the request. But the username is not an attribute of the request; it's an environment variable on its own that's being set by Apache once the request has already been processed. That's why it doesn't work the way you want it to.

There's a workaround you can do by taking the REMOTE_USER environment variable and putting it in a header:

RequestHeader set X-Remote-User expr=%{REMOTE_USER}
SetEnvIf X-Remote-User "marco" MYENV=foobar
Related Topic