SetEnv 指令
說明 設定環境變數
文法 SetEnv env-variable value
SetEnvIf 指令
說明 根據用戶端請求屬性設定環境變數
文法 SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
範圍 server config, virtual host, directory, .htaccess
SetEnvIf指令根據用戶端的請求屬性設定環境變數。第一個參數attribute必須是下列三種類別之一:
一個HTTP要求標頭域(參見RFC2616);例如:Host, User-Agent, Referer, Accept-Language 。可以用一個Regex來進行匹配。
下列請求屬性之一:
Remote_Host 遠程主機名稱(若可用)
Remote_Addr 遠程主機IP地址
Server_Addr 接收到請求的伺服器IP地址(2.0.43及以後版本)
Request_Method 所用的要求方法(GET, POST等等)
Request_Protocol 請求所使用的協議及其版本("HTTP/0.9", "HTTP/1.0", "HTTP/1.1"等)
Request_URI 在HTTP請求行中請求的資源(通常是URL中去除協議、主機以及查詢字串後剩餘的部分)。
列出的與該請求關聯的環境變數名字中的一個。這將允許SetEnvIf指令基於預先匹配的結果進行測試。只有那些由較早的SetEnvIf[NoCase]指令定義的環境變數才可以按照這種方式測試。"較早的"意思是它們在更上層的範圍(比如全域範圍)中被定義或者在同一範圍中較早出現。只有在請求的屬性未能得到匹配並且attribute沒有使用Regex的時候,環境變數才會被考慮。
如:不記錄192.168.7.139的訪問日誌
首先設定環境變數 SetEnvIf Remote_Addr "192.168.7.139" dontlog
使用上面設定的環境變數
CustomLog "logs/access_log" common env=!dontlog
SetEnvIfNoCase
說明: Sets environment variables based on attributes of the request without respect to case
文法: SetEnvIfNoCase attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
上下文: 伺服器配置, 虛擬機器主機, 目錄, .htaccess
覆蓋項: FileInfo
狀態: Base
模組: mod_setenvif
相容性: Apache 1.3 and above
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:
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 included and contained Apache.Org, apache.org, or any other combination.
SetEnvIfNoCase 當滿足某個條件時,為變數賦值,一般結合其他指令使用。
如:
1。SetEnvIf Request_URI "/logo(.)+" local_ref=0
Allow from env=local_ref 當local_ref有值時,可以訪問。
2。SetEnvIfNoCase Request_URI .js$ useless-file
CustomLog logs/hebgc.com/access.log combined env=!useless-file
當滿足條件時才記錄日誌。