我们希望能够在Apache中基于User-Agent设置Cache-Control头
例如,如果User-Agent包含子stringfoo
我们要将Cache-Control设置为10分钟。 但是如果没有设置为1天。
search周围,我发现BrowserMatch
,但似乎只设置环境variables:
BrowserMatch foo short-live # Sets environment variable short-live
但我想有条件地应用像Header set ...
或ExpiresDefault ...
指令ExpiresDefault ...
有没有办法有条件地申请声明? 就像是:
<FilesMatch "\.(jpg|jpeg|gif|png|js|css)$"> Header set Cache-control "max-age=86400" <IfBrowser "foo"> Header set Cache-control "max-age=600" </IfBrowser> </FilesMatch>
请注意, IfBrowser
是虚构的。 有没有真正的指令可以这样使用? 谢谢!
PS这是从https://stackoverflow.com/questions/5708090/contional-declaration-in-apache-httpd转发,因为它收到了一点活动。
更新 – 是以前的代码不好。 但是,这可能会使你朝着正确的方向发展:
Header set Cache-control "max-age=86400" SetEnvIfNoCase User-Agent libwww short-cache Header set Cache-control "max-age=600" env=short-cache
我已经testing了这个,它似乎工作。