## The

Syntax: SetEnvIf attribute regex envar[=value] [...]
Default: none
Context: server config
Override: none
Status: Base
Module: mod_setenvif
Compatibility: Apache 1.3 and above; the Request_Protocol keyword and environment-variable matching are only available with 1.3.7 and later

The `SetEnvIf` directive defines environment variables based on attributes of the request. These attributes can be the values of various HTTP request header fields (see RFC2068 for more information about these), or of other aspects of the request, including the following:

- `Remote_Host` - the hostname (if available) of the client making the request
- `Remote_Addr` - the IP address of the client making the request
- `Remote_User` - the authenticated username (if available)
- `Request_Method` - the name of the method being used (`GET`, `POST`, et cetera)
- `Request_Protocol` - the name and version of the protocol with which the request was made (e.g., "HTTP/0.9", "HTTP/1.1", etc.)
- `Request_URI` - the portion of the URL following the scheme and host portion

Some of the more commonly used request header field names include `Host`, `User-Agent`, and `Referer`.

If the attribute name doesn't match any of the special keywords, nor any of the request's header field names, it is tested as the name of an environment variable in the list of those associated with the request. This allows `SetEnvIf` directives to test against the result of prior matches.

> Only those environment variables defined by earlier `SetEnvIf[NoCase]` directives are available for testing in this manner. 'Earlier' means that they were defined at a broader scope (such as server-wide) or previously in the current directive's scope.

Example:

       SetEnvIf Request_URI "\.gif$" object_is_image=gif
       SetEnvIf Request_URI "\.jpg$" object_is_image=jpg
       SetEnvIf Request_URI "\.xbm$" object_is_image=xbm
            :
       SetEnvIf Referer www\.mydomain\.com intra_site_referral
            :
       SetEnvIf object_is_image xbm XBIT_PROCESSING=1

The first three will set the envariable `object_is_image` if the request was for an image file, and the fourth sets `intra_site_referral` if the referring page was somewhere on the `www.mydomain.com` Web site.