ExpiresActive On .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,但是然后呢?
谢谢!
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。 mod_expires 允许根据类型轻松设置过期规则。
但过期时间仅指定某个响应的新鲜时间。这并不一定意味着响应是可缓存的。但一般来说,任何成功的响应都是可缓存的,除非有限制:
因此,除非您指定根本不存储响应(即使用
no-store
),否则响应可能会由公共缓存(共享缓存)和私有缓存(本地缓存)存储。响应的新鲜时间可以使用绝对时间值(例如“2010-10-09”)或相对时间值(例如“明天”)来表示。日期格式
A2592000
使用后一个时间值,因为A
表示访问时间,2592000
是访问时间的秒数被添加。因此,A2592000
表示“自访问时间起 2592000 秒”。Apache 有一些特殊用途的环境变量,其中
force-no-vary
是其中之一:现在 Vary 标头字段 用于指定服务器用于的 头字段名称列表从多个表示中选择响应:
因此,如果您正在使用内容协商,并且请求了像
/document.html
这样的通用 URL,并且该资源有多种表示形式(例如英语和德语),并且您的服务器会选择德语变体作为Accept-Language 声明值de
,服务器将包含一个包含Accept-Language
的 Vary 字段,以让缓存知道选择是基于Accept-Language的值。但有些用户代理没有正确理解这一点。在这种情况下,不应发送 Vary 标头字段,这可以通过设置特殊用途环境变量
force-no-vary
来完成。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:
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).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 asA
denotes access time and2592000
is the number of seconds that are added. SoA2592000
means “2592000 seconds from the time of access on”.Apache has some special purpose environment variables where
force-no-vary
is one of them: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:
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 valuede
, the server would include a Vary field containingAccept-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
.ExpiresByType 是 mod_expires 模块的 Apache 指令,用于生成“Expires”和“Cache-control”http 响应标头。这些标头告诉浏览器允许将资源缓存特定的时间。
从文档( http://httpd.apache.org/docs/2.0/mod /mod_expires.html ) :
同一页面中的示例可能会解释以下内容:
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 ) :
An example from the same page might explain things: