Module mod_setenvif
Module mod_setenvif supports directives for the IBM® HTTP Server for i Web server.
Summary
The mod_setenvif module allows you to set environment variables if different aspects of the request match regular expressions that you specify. These variables can be used by other parts of the server to make decisions about actions to be taken.
The directives are considered in the order they appear in the configuration. So more complex sequences can be used, such as this example, which sets Netscape if the browser is Mozilla but not MSIE.
BrowserMatch ^Mozilla netscape
BrowserMatch MSIE !netscape
Directives
BrowserMatch
Module: mod_setenvif | |
Syntax: BrowserMatch regex envar[=value] [...] | |
Default: none | |
Context: server config, virtual host, directory, .htaccess | |
Override: none | |
Origin: Apache | |
Example: BrowserMatch ^Mozilla forms jpeg=yes browser=netscape |
BrowserMatch defines environment variables based on the User-Agent HTTP request header field. The first argument should be a POSIX.2 extended regular expression (similar to an egrep-style regex). The rest of the arguments give the names of variables to set, and optional values to which they should be set. These take the form of the following:
- varname
- !varname
- varname=value
See Environment variables set by HTTP Server for more information.
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 value given by value. If a User-Agent string matches more than one entry, they will be merged. Entries are processed in the order in which they appear, and later entries can override earlier ones. For example:
BrowserMatch ^Mozilla forms jpeg=yes browser=netscape
BrowserMatch ^Mozilla/[2-3]" tables agif frames javascript
BrowserMatch MSIE !javascript
In the above example, if the User-Agent field is Mozilla, the environment variables forms, jpeg=yes and browser=netscape will be set. If the request is Mozilla/2 or Mozilla/3, then in addition to the environment variables on the first BrowserMatch directive, the variables tables, agif, frames and javascript will be set.
BrowserMatchNoCase Robot is_a_robot
SetEnvIfNoCase User-Agent Robot is_a_robot
- Parameter One: regex
- The regex parameter is a case-sensitive POSIX.2 extended regular expression. This gives the user the ability to select variants on the User-Agent field, such as using some wildcarding to group versions of a client browser. See Environment variables set by HTTP Server for more information.
- Parameter Two: envvar[=value]
- The envvar[=value] parameter gives the names of the variables to set and, optional, values to which they should be set. The case is preserved when lowercase characters are specified. Valid values include all EBCDIC characters. The value must be enclosed in quotation marks if it contains any non-alphanumeric character or blanks.
BrowserMatchNoCase
Module: mod_setenvif | |
Syntax: BrowserMatchNoCase regex envar[=value] [...] | |
Default: none | |
Context: server config, virtual host, directory, .htaccess | |
Override: none | |
Origin: Apache | |
Example: BrowserMatchNoCase ibm platform=ibm |
BrowserMatchNoCase is semantically identical to BrowserMatch. However, it provides for case-insensitive matching. For example:
BrowserMatchNoCase mac platform=ibm
BrowserMatchNoCase win platform=windows
BrowserMatch and BrowserMatchNoCase are special cases of SetEnvIf and SetEnvIfNoCase. The following two lines have the same effect:
BrowserMatchNoCase Robot is_a_robot
SetEnvIfNoCase User-Agent Robot is_a_robot
- Parameter One: regex
- The regex parameter is a case-insensitive POSIX.2 extended regular expression. This gives the user the ability to select variants on the User-Agent field, such as using some wildcarding to group version of a client browser. See Environment variables set by HTTP Server for more information.
- Parameter Two: envvar[=value]
- The envvar[=value] parameter gives the names of variables to set and, optionally, values to which they should be set. They can take the form of 'varname', '!varname' or 'varname=value'. The case is preserved when lowercase characters are specified. Valid values include all EBCDIC characters. The value must be enclosed in quotation marks if it contains any non-alphanumeric character or blanks.
SetEnvIf
Module: mod_setenvif | |
Syntax: SetEnvIf attribute regex envar[=value] [...] | |
Default: none | |
Context: server config, virtual host, directory, .htaccess | |
Override: none | |
Origin: Apache | |
Example: SetEnvIf Request_URI "\.gif$" object_is_image=gif |
SetEnvIf defines environment variables based on attributes of the request. These attributes can be the values of various HTTP request header fields or of other aspects of the request. See RFC2068 for more information.
Attribute | Description |
---|---|
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). |
Request_Protocol | The name of the method being used (GET, POST). |
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 Referrer.
If the attribute name does not match any of the special keywords, or 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 in a broader context (such as server-wide) or previously in the current directive's context. For 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 Referrer www\.mydomain\.com intra_site_referral
:
SetEnvIf object_is_image xbm XBIT_PROCESSING=1
The first three will set the environment variable 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. The 5th statement of the example sets XBIT processing, if the environment variable object_is_image was set by the directive.
- Parameter One: attribute
- The attribute parameter is the attribute of the request, such as an HTTP header value. The attribute can also be an environment variable that was set by an earlier SETENVIF directive.
- Parameter Two: regex
- The regex parameter is a case-sensitive POSIX.2 extended regular expression. This gives the user the ability to select variants on the Attribute field, such as using some wildcarding to group related values, and use those to set the environment variables. See Environment variables set by HTTP Server for more information.
- Parameter Three: envvar[=value]
- The envvar[=value] gives the names of variables to set and, optionally, values to which they should be set. They take the form of 'varname', '!varname' or 'varname=value'. The case is preserved when lowercase characters are specified. Valid values include all EBCDIC characters. The value must be enclosed in quotation marks if it contains any non-alphanumeric character or blanks.
SetEnvIfNoCase
Module: mod_setenvif | |
Syntax: SetEnvIfNoCase attribute regex envar[=value] [...] | |
Default: none | |
Context: server config, virtual host, directory .htaccess | |
Override: none | |
Origin: Apache | |
Example: SetEnvIfNoCase Host IBM\.Org site=ibm |
SetEnvIfNoCase is semantically identical to SetEnvIf, and differs only in that the regular expression matching is performed in a case-insensitive manner. For example:
SetEnvIfNoCase Host QIBM\.Org site=ibm
This will cause the site variable to be set to 'ibm' if the HTTP request header field Host: was included and contained QIBM.Org, qibm.org, or any other combination.
- Parameter One: attribute
- The attribute parameter is the attribute of the request, such as an HTTP Header value. The attribute can also be an environment variable that was set by an earlier setenvif directive.
- Parameter Two: regex
- The regex parameter is a case-sensitive POSIX.2 extended regular expression. This gives the user the ability to select variants on the Attribute field, such as using some wildcarding to group related values, and use those to set the environment variables. See Environment variables set by HTTP Server for more information.
- Parameter Three: envvar[=value]
- The envvar[=value] parameter gives the names of variables to set and, optionally, values to which they should be set. They take the form of 'varname', '!varname' or 'varname=value'. The case is preserved when lowercase characters are specified. Valid values include all EBCDIC characters. The value must be enclosed in quotation marks if it contains any non-alphanumeric character or blanks.