apache - ExpiresActive On .htaccess 解释

标签 apache .htaccess

[i]ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
BrowserMatch "MSIE" brokenvary=1
BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
BrowserMatch "Opera" !brokenvary
SetEnvIf brokenvary 1 force-no-vary[/i]

最近在示例 .htaccess 中看到了此代码。

大概 ExpiresByType 设置图像的到期时间 - 这与访问者浏览器缓存有关吗?什么是 A2592000 翻译成?

“brokenvary=1”是什么意思?我收集它正在寻找一个 UserAgent,但是然后呢?

谢谢!

最佳答案

Presumably ExpiresByType sets an expiry time on images - is that related to the visitors browser cache?



是的。 mod_expires允许根据类型轻松设置过期规则。

但是过期时间只指定了某个响应的新鲜时间。这并不一定意味着 response is cacheable .但是in general, any successful response is cacheable unless there are restrictions :

Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entry, MAY return it without validation if it is fresh, and MAY return it after successful validation.



因此,除非您指定根本不存储响应(即使用 no-store ),否则响应可能由公共(public)缓存(共享缓存)和私有(private)缓存(本地缓存)存储。

And what does A2592000 translate to?



响应的新鲜时间可以使用绝对时间值(例如“2010-10-09”)或相对时间值(例如“明天”)来表示。日期格式A2592000使用后一个时间值作为 A表示访问时间,2592000是添加的秒数。所以A2592000表示“从访问时间开始 2592000 秒”。

And what does the "brokenvary=1" imply? I gather it's looking for a UserAgent, but then what?



Apache 有一些 special purpose environment variables在哪里 force-no-vary 是其中之一:

This causes any Vary fields to be removed from the response header before it is sent back to the client. Some clients don't interpret this field correctly; setting this variable can work around this problem. Setting this variable also implies force-response-1.0.



现在Vary header field用于指定 list of header field names the server used to select the response among multiple representations :

A server SHOULD use the Vary header field to inform a cache of what request-header fields were used to select among multiple representations of a cacheable response subject to server-driven negotiation.



因此,如果您使用内容协商和请求的通用 URL,如 /document.html被请求并且该资源有多种表示形式(例如,英语和德语)并且您的服务器选择德语变体,因为 Accept-Language 声明值 de ,服务器将包含一个 Vary 字段,其中包含 Accept-Language让缓存知道选择是基于 Accept-Language 的值。

但是一些用户代理没有做到这一点。在这种情况下,不应该发送 Vary 头字段,这可以通过设置专用环境变量 force-no-vary 来完成。 .

关于apache - ExpiresActive On .htaccess 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890000/

相关文章:

apache - mod_rewrite 和 HTTP 基本身份验证

java - 如何手动运行 netbeans webapp

php - 通过 htaccess 为登录用户强制 https

php - 此行在此 .htaccess 文件中做什么?此文件中的其他行看起来安全吗?

css - Rails 4 字体在 Apache 上的生产中预编译后不呈现

mysql - XAMPP 访问被拒绝

python - 模组安全 : Output filter: Failed to read bucket (rc 104): Connection reset by peer

.htaccess - 开发桌面 SSL 连接错误

.htaccess - 站点子目录充当根目录?我应该永久重定向 301 吗?

.htaccess - Codeigniter 删除 https 上的 index.php