我想使用 apache 配置文件为 MSIE 设置一些标头。我该如何设置条件?
# better website experience for ie users
<IfModule mod_headers.c && MSIE> # && MSIE is just exmple. WRONG
Header set X-UA-Compatible "IE=Edge,chrome=1"
# mod_headers can't match by content-type, but we don't want to send this header on *everything*...
<FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
Apache 2.2
答案1
您必须先检查浏览器,然后设置环境变量。然后,环境变量将成为您可以采取行动的条件,方法是设置标头或(如果您愿意)执行其他操作。以下是一个例子:
BrowserMatch ".*MSIE.*" IE_browser=yes
Header set X-UA-Compatible "IE=Edge,chrome=1" env=IE_browser
<FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
Header unset X-UA-Compatible
</FilesMatch>