ExpiresActive On .htaccess 解释

发布于 2024-09-26 11:59:04 字数 484 浏览 1 评论 0原文

[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,但是然后呢?

谢谢!

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

saw this code in a sample .htaccess recently.

Presumably ExpiresByType sets an expiry time on images - is that related to the visitors browser cache? and what does A2592000 translate to?

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

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十二 2024-10-03 11:59:04

大概 ExpiresByType 设置了图像的过期时间 - 这与访问者浏览器缓存有关吗?

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

但过期时间仅指定某个响应的新鲜时间。这并不一定意味着响应是可缓存的。但一般来说,任何成功的响应都是可缓存的,除非有限制:

除非受到缓存控制的特别限制(14.9< /a>) 指令,缓存系统可以始终存储成功的响应(请参阅 13.8)作为缓存条目,如果是新鲜的,可以在不验证的情况下返回它,并且可以在成功验证后返回它。

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


A2592000 翻译成什么?

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


“brokenvary=1”意味着什么?我推测它正在寻找 UserAgent,但是然后呢?

Apache 有一些特殊用途的环境变量,其中force-no-vary 是其中之一:

这会导致在将响应标头发送回客户端之前将所有 Vary 字段从响应标头中删除。有些客户不能正确解释该字段;设置这个变量可以解决这个问题。设置此变量还意味着force-response-1.0

现在 Vary 标头字段 用于指定服务器用于的 头字段名称列表从多个表示中选择响应

服务器应该使用 Vary 标头字段来通知缓存哪些请求标头字段用于在可缓存响应的多种表示形式中进行选择,并服从服务器驱动的协商。

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

但有些用户代理没有正确理解这一点。在这种情况下,不应发送 Vary 标头字段,这可以通过设置特殊用途环境变量 force-no-vary 来完成。

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

Yes. mod_expires allows an easy setup of expiration rules based on the type.

But the expiration time specifies only the freshness time of a certain response. This does not necessarily mean that the response is cacheable. But 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.

So unless you specify the response not to be stored at all (i.e. using no-store), the response may be stored by both public caches (shared caches) and private caches (local caches).


And what does A2592000 translate to?

The freshness time of a response can be expressed using either an absolute time value (e.g “2010-10-09”) or a relative time value (e.g. “tomorrow”). The date format A2592000 uses a latter time value as A denotes access time and 2592000 is the number of seconds that are added. So A2592000 means “2592000 seconds from the time of access on”.


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

Apache has some special purpose environment variables where force-no-vary is one of them:

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.

Now the Vary header field is used to specify a 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.

So if you’re using content negotiation and a requested generic URL like /document.html is requested and there are multiple representations of that resource (e.g. in English and German) and your server selects the German variant as Accept-Language states the value de, the server would include a Vary field containing Accept-Language to let the caches know that the selection was based on the value of Accept-Language.

But some user agents don’t get this right. And in that cases the Vary header field should not be sent that can be done by setting the special purpose environment variable force-no-vary.

仅一夜美梦 2024-10-03 11:59:04

ExpiresByType 是 mod_expires 模块的 Apache 指令,用于生成“Expires”和“Cache-control”http 响应标头。这些标头告诉浏览器允许将资源缓存特定的时间。

从文档( http://httpd.apache.org/docs/2.0/mod /mod_expires.html ) :

'A' means the client's access time should be used.

同一页面中的示例可能会解释以下内容:

# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType image/gif A2592000
# HTML documents are good for a week from the
# time they were changed
ExpiresByType text/html M604800

ExpiresByType is an Apache Directive of the mod_expires module that generates 'Expires' and 'Cache-control' http response headers. These headers tell a browser that it is allowed to cache the resource for a specific amount of time.

From the documententation ( http://httpd.apache.org/docs/2.0/mod/mod_expires.html ) :

'A' means the client's access time should be used.

An example from the same page might explain things:

# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType image/gif A2592000
# HTML documents are good for a week from the
# time they were changed
ExpiresByType text/html M604800
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文