A useful apache command SetEnvIf

Source: Internet
Author: User
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

SetEnvIfCommandSet environment variables based on client request properties. TheOneParametersAttributeIt must be one of the following three categories:

  1. OneHTTP Request Header domain (see RFC2616); for example:Host,User-Agent,Referer,Accept-Language. AvailableOneRegular Expressions.
  2. One of the following request attributes:
    • Remote_HostRemote Host name (if available)
    • Remote_AddrRemote Host IP Address
    • Server_AddrIP address of the server that received the request (2.0.43 and later)
    • Request_MethodThe request method used (GET,POSTAnd so on)
    • Request_ProtocolThe protocol used by the request and its version ("HTTP/0.9", "HTTP/1.0", "HTTP/1.1", etc)
    • Request_URIResources requested in the HTTP request line (usually the rest of the protocol, host, and query string are removed from the URL ).
  3. In the list of environment variables associated with the requestOne. This will allowSetEnvIfCommandTests 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.

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.