开发者

Conditional declaration in Apache httpd

开发者 https://www.devze.com 2023-02-27 01:10 出处:网络
We want to be able to set Cache-Control headers based on User-Agent in Apache For example, if a User-Agent contains substring foo we want to set Cache-Control to 10 minutes. But if not set it to 1 开

We want to be able to set Cache-Control headers based on User-Agent in Apache

For example, if a User-Agent contains substring foo we want to set Cache-Control to 10 minutes. But if not set it to 1 开发者_StackOverflow社区day.

Searching around, I've found BrowserMatch, but that seems to only set environment variables:

BrowserMatch foo short-live  # Sets environment variable short-live

But I would like to conditionally apply a directive like Header set ... or ExpiresDefault ...

Is there a way to conditionally apply declarations? Something like:

<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>

Note, IfBrowser is fictional. Is there any real directive that could be used like this? Thanks!


Aha, thanks to @muffinista at ServerFault who found the solution:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号