SetEnv command description environment variable syntax SetEnvenv-variablevalueSetEnvIf command description environment variable syntax SetEnvIfattributeregex according to client request properties [!] Env-variable [value] [[!] Env-variable [value]... scope serverconfig, virtualhost, d
SetEnv command description SetEnv env-variable value SetEnvIf environment variable syntax SetEnvIf attribute regex [!] Env-variable [= value] [[!] Env-variable [= value]... scope server config, virtual host, d
SetEnvCommand
Description |
Set Environment Variables |
Syntax |
SetEnv env-variable value |
SetEnvIf
Command
Description |
Set environment variables based on client request Properties |
Syntax |
SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ... |
Scope |
Server config, virtual host, directory,. htaccess |
SetEnvIf
CommandSet environment variables based on client request properties. TheOneParametersAttributeIt must be one of the following three categories:
- OneHTTP Request Header domain (see RFC2616); for example:
Host
,User-Agent
,Referer
,Accept-Language
. AvailableOneRegular Expressions.
- One of the following request attributes:
Remote_Host
Remote Host name (if available)
Remote_Addr
Remote Host IP Address
Server_Addr
IP address of the server that received the request (2.0.43 and later)
Request_Method
The request method used (GET
,POST
And so on)
Request_Protocol
The protocol used by the request and its version ("HTTP/0.9", "HTTP/1.0", "HTTP/1.1", etc)
Request_URI
Resources requested in the HTTP request line (usually the rest of the protocol, host, and query string are removed from the URL ).
- In the list of environment variables associated with the requestOne. This will allow
SetEnvIf
CommandTests are performed based on pre-matching results. Only thoseSetEnvIf[NoCase]
CommandThe defined environment variables can be tested in this way. "Earlier" means they are defined in the upper-level scope (such as the global scope) or appear earlier in the same scope. Only when the requested property does not match andAttributeEnvironment variables are considered only when regular expressions are not used.
For example, access logs of 192.168.7.139 are not recorded.
First, set the environment variable SetEnvIf Remote_Addr "192 \. 168 \. 7 \. 139" dontlog
Use the environment variables set above
CustomLog "logs/access_log" common env =! Dontlog
SetEnvIfNoCase
Sets: Sets environment variables based on attributes of the request without respect to case
Syntax: SetEnvIfNoCase attribute regex [!] Env-variable [= value] [[!] Env-variable [= value]...
Context: server configuration, virtual host, directory,. htaccess
Overwrite: FileInfo
Status: Base
Module: mod_setenvif
Compatibility: Apache 1.3 and above
The SetEnvIfNoCase is semantically identical to the SetEnvIf direve ve, and differs only in that the regular expression matching is already med in a case-insensitive manner. For example:
SetEnvIfNoCase Host Apache \. Org site = apache
This will cause the site environment variable to be set to "apache" if the HTTP request header field Host: was encoded and contained Apache. Org, apache.org, or any other combination.
SetEnvIfNoCase: assign values to variables when a condition is met.Command.
For example:
1. SetEnvIf Request_URI "/logo (.) +" local_ref = 0
Allow from env = local_ref can be accessed when local_ref has a value.
2. SetEnvIfNoCase Request_URI. js $ useless-file
CustomLog logs/hebgc.com/access.log combined env =! Useless-file
Logs are recorded only when conditions are met.