A useful apache command SetEnvIf

Source: Internet
Author: User

SetEnv command
Set Environment Variables
Syntax SetEnv env-variable value

SetEnvIf command
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

The SetEnvIf command sets environment variables based on the client's request attributes. The first attribute parameter must be in one of the following three categories:

An HTTP request header domain (see RFC2616); for example, Host, User-Agent, Referer, and Accept-Language. A regular expression can be used for matching.
One of the following request attributes:
Remote_Host remote host name (if available)
Remote_Addr Remote Host IP Address
Server_Addr receives the requested Server IP address (2.0.43 and later versions)
Request methods used by Request_Method (GET, POST, etc)
The protocol used by the Request_Protocol request and its version ("HTTP/0.9", "HTTP/1.0", "HTTP/1.1", etc)
Request_URI is the resource requested in the HTTP request line (usually the rest of the protocol, host, and query string are removed from the URL ).
Name of the environment variable associated with the request. This will allow the SetEnvIf command to perform tests based on pre-matching results. Only the environment variables defined by the earlier SetEnvIf [NoCase] command 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. Environment variables are considered only when the Requested attribute is not matched and the attribute does not use a regular expression.

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. It is generally used in conjunction with other commands.
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.