apache - Apache httpd 中的条件声明

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

我们希望能够根据 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/

相关文章:

java - log4j2 设置 Async Logger 和 Async Appender 的线程数

c# - 从 web.config 获取连接字符串以在 EF POCO 中使用?

c# - 使用最小配置的 Unity

apache - 为什么 apache 服务器 redicect/doc 到 usr/share/doc

android - 从 Apache 服务器在 Android 上播放 MP4 视频时出现问题

php - 使用 volley 和 php 将 android 连接到 mysql 时禁止错误 403

asp.net - 具有长时间运行的同步请求的 ASP.NET 应用程序的注意事项

mysql - 主机HOST不支持SSL连接

javascript - 从客户端 js SPA 中的 web.config 读取 Api Key 值

django - Apache 2 :/etc/apache2/sites-available is missing on macos