【问题标题】:Conditional declaration in Apache httpdApache httpd 中的条件声明
【发布时间】:2011-08-08 03:54:27
【问题描述】:

我们希望能够基于 Apache 中的 User-Agent 设置 Cache-Control 标头

例如,如果 User-Agent 包含子字符串 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 是虚构的。有没有可以像这样使用的真正指令?谢谢!

【问题讨论】:

标签: apache configuration web-config user-agent apache-config


【解决方案1】:

啊哈,感谢 ServerFault 的 @muffinista 找到了解决方案:

Header set Cache-control "max-age=86400"
BrowserMatch foo short-cache
Header set Cache-control "max-age=600" env=short-cache

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多