apache.htaccesshttpd.confsetenv

Override or unset a variable set with SetEnvIfNoCase


I use the following code in my httpd.conf to block some unwanted old browsers

SetEnvIfNoCase User-Agent (msie\s7) blocked=old

Order Allow,Deny
Allow from all
Deny from env=blocked

The following useragent however should not be blocked (Microsoft Office uses this useragent):

mozilla/4.0 (compatible; msie 7.0; windows nt 6.1; win64; x64; trident/7.0; .net clr 2.0.50727; slcc2; .net clr 3.5.30729; .net clr 3.0.30729; media center pc 6.0; .net4.0c; .net4.0e; ms-office; msoffice 16)

Question: How do I override or unset a variable set with SetEnvIfNoCase?

Will this work?

SetEnvIfNoCase User-Agent (msoffice) blocked=0

Solution

  • An exclamation mark will remove a variable if already defined:

    SetEnvIfNoCase User-Agent (msoffice) !blocked
    

    Source: https://httpd.apache.org/docs/2.4/mod/mod_setenvif.html