GCS Amplitude
GCS Amplitude

Apache Module mod_setenvif

module allows you to set internal environment variables according to whether different aspects of the request match regular expressions you specify. These environment variables can be used by other parts of the server to make decisions about actions to be taken, as well as becoming available to CGI scripts and SSI pages.mod_setenvif

The directives are considered in the order they appear in the configuration files. So more complex sequences can be used, such as this example, which sets netscape

if the browser is mozilla but not MSIE.

When the server looks up a path via an internal subrequest such as looking for a

or generating a directory listing with DirectoryIndex

, per-request environment variables are mod_autoindexnot inherited in the subrequest. Additionally,

directives are not separately evaluated in the subrequest due to the API phases SetEnvIf

takes action in.mod_setenvif

BrowserMatch regex [!]env-variable[=value] [[!]env-variable[=value]] ...

BrowserMatchNoCase Robot isarobot SetEnvIfNoCase User-Agent Robot isarobot

BrowserMatch ^Mozilla forms jpeg=yes browser=netscape BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript BrowserMatch MSIE !javascript

BrowserMatchNoCase mac platform=macintosh BrowserMatchNoCase win platform=windows

. A regular expression may be used to specify a set of request headers.Remote_Host

- the hostname (if available) of the client making the requestRemote_Addr

- the IP address of the client making the requestServer_Addr

- the IP address of the server on which the request was received (only with versions later than 2.0.43)Request_Method

- the name of the method being used (GET

- the name and version of the protocol with which the request was made (Request_URI

- the resource requested on the HTTP request line -- generally the portion of the URL following the scheme and host portion without the query string. See the RewriteCond

for extra information on how to match your query string.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. Environment variables will be considered only if there was no match among request characteristics and a regular expression was not used for the The second argument (regex) is a regular expression. If the regex matches against the attribute, then the remainder of the arguments are evaluated.

The rest of the arguments give the names of variables to set, and optionally values to which they should be set. These take the form of

In the first form, the value will be set to "1". The second will remove the given variable if already defined, and the third will set the variable to the literal value given by

. Since version 2.0.51, Apache httpd will recognize occurrences of value$1

within value and replace them by parenthesized subexpressions of regex.

SetEnvIf RequestURI "\.gif$" objectisimage=gif SetEnvIf RequestURI "\.jpg$" objectisimage=jpg SetEnvIf RequestURI "\.xbm$" objectisimage=xbm SetEnvIf Referer www\.mydomain\.example\.com intrasitereferral SetEnvIf objectisimage xbm XBITPROCESSING=1 SetEnvIf ^TS ^[a-z] HAVE_TS

if the request was for an image file, and the fourth sets intrasitereferral

if the referring page was somewhere on the www.mydomain.example.com

if the request contains any headers that begin with "TS" whose values begins with any character in the set [a-z].

SetEnvIfExpr "tolower(req('X-Sendfile')) == 'd:\images\verybig.iso')" isodelivered

every time our application attempts to send it via X-Sendfile

A more useful example would be to set the variable rfc1918 if the remote IP address is a private address according to RFC 1918:

SetEnvIfExpr "-R '10.0.0.0/8' || -R '172.16.0.0/12' || -R '192.168.0.0/16'" rfc1918

can be used to achieve similar results.mod_filter

This will cause the site

was included and contained Example.Org

Modules | Directives | FAQ | Glossary | Sitemap

Apache HTTP Server Version 2.4

Apache Module mod_setenvif

Available Languages: en | fr | ja | ko | tr

BrowserMatch Directive

The BrowserMatch is a special cases of the SetEnvIf directive that sets environment variables conditional on the User-Agent HTTP request header. The following two lines have the same effect:

BrowserMatchNoCase Directive

The BrowserMatchNoCase directive is semantically identical to the BrowserMatch directive. However, it provides for case-insensitive matching. For example:

SetEnvIf Directive

The SetEnvIf directive defines environment variables based on attributes of the request. The attribute specified in the first argument can be one of four things:

SetEnvIfExpr Directive

The SetEnvIfExpr directive defines environment variables based on an ap_expr. These expressions will be evaluated at runtime, and applied env-variable in the same fashion as SetEnvIf.

SetEnvIfNoCase Directive

The SetEnvIfNoCase is semantically identical to the SetEnvIf directive, and differs only in that the regular expression matching is performed in a case-insensitive manner. For example: