标题:一个很有用的apache指令SetEnvIf 出处:沧海一粟 时间:Tue, 14 Jul 2009 13:29:55 +0000 作者:jed 地址:http://www.dzhope.com/post/631/ 内容: 语法SetEnv env-variable value 语法SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ... SetEnvIf指令根据客户端的请求属性设置环境变量。第一个参数attribute必须是下列三种类别之一: 一个HTTP请求头域(参见RFC2616);例如:Host, User-Agent, Referer, Accept-Language 。可以用一个正则表达式来进行匹配。下列请求属性之一: 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没有使用正则表达式的时候,环境变量才会被考虑。 如:不记录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: 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有值时,可以访问。 当满足条件时才记录日志。 Generated by Bo-blog 2.1.1 Release