我们希望能够根据 Apache 中的 User-Agent 设置 Cache-Control header
例如,如果用户代理包含子字符串 foo
,我们希望将 Cache-Control 设置为 10 分钟。但如果不设置为 1 天。
四处搜索,我找到了BrowserMatch
,但这似乎只能设置环境变量:
BrowserMatch foo short-live # Sets environment variable short-live
但我想有条件地应用诸如 Header set ...
或 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
是虚构的。有没有真正的指令可以像这样使用?谢谢!
最佳答案
啊哈,感谢 ServerFault 的 @muffinista 找到了解决方案:
Header set Cache-control "max-age=86400"
BrowserMatch foo short-cache
Header set Cache-control "max-age=600" env=short-cache
关于apache - Apache httpd 中的条件声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5708090/