之间有三个的.htaccess到期规则差异 [英] Difference between three .htaccess expire rules

查看:202
本文介绍了之间有三个的.htaccess到期规则差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是以下三个的.htaccess规则以及何时使用各个之间的差异,有没有什么特殊的用例prefers一个比其他?

 头设置缓存控制最大年龄= 290304000
标题设定过期星期四,2020年4月15日20:00:00 GMT
ExpiresDefault进入加10年
 

解决方案

标题 是的 mod_headers中,允许修改HTTP报头字段。在这种情况下头设置有效地设置所提到的头字段的 的Cache-Control 和的 过期,让一个已经存在的头字段将被覆盖。

第一个指令设置的头字段的的Cache-Control 的与值最大年龄= 290304000 ,描述了新鲜的寿命是290304000相对于响应时间秒

在对比的是,第二个指令集的头字段的过期的与值周四,2020年4月15号20:00:00 GMT 描述与绝对时间值的新鲜度一生。

的Cache-Control 的的最大年龄的值和的过期的期满时间戳可以转化为其他:在

  

4.2.1。计算保鲜寿命

     

一个缓存可以计算出新鲜感寿命(表示为     freshness_lifetime)使用的第一场比赛的响应     以下内容:

     
      
  •   
  • 如果最大年龄响应指令(第5.2.2.8 )是present,    利用它的价值,或

  •   
  • 如果过期响应头字段( 5.3节)是present,使用    其值减去日期响应头字段的值,或

  •   
  •   

但是,如果两者都present,的Cache-Control 最大年龄的是preferred过的过期

  

如果响应包括与max-age的一个缓存控制领域     指令(第5.2.2.8 ),接收方必须忽略过期     领域。同样地,如果一个响应包括的s的MaxAge指令     (第5.2.2.9 ),共享缓存接收者必须忽略过期     领域。在这两种情况下,在截止日期的值是仅用于     收件人尚未实施的缓存控制领域。

不用手动设置这些HTTP缓存控制头字段, mod_expires ExpiresDefault 指令可简单设置为HTTP缓存。该保鲜寿命可以用绝对值或相对值来描述,无论是相对于响应时间(即访问 / 现在)或相对于所需的文件的修改时间(即修改)。它同时使用的的Cache-Control 过期的。

在这种情况下,第三指令设置默认的保鲜寿命为10年,从响应的时间。

我会用与标题做手工的mod_expires为HTTP缓存控制来代替。这是更为方便,允许相对和绝对新鲜的时间和同时使用的的Cache-Control 过期的。

What's the difference between the following three .htaccess rules and when to use each, is there any special use cases that prefers one over the other?:

Header set Cache-Control "max-age=290304000"
Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT"
ExpiresDefault "access plus 10 years"

解决方案

Header is a directive of mod_headers that allows to modify HTTP header fields. In this case Header set effectively sets the mentioned header fields Cache-Control and Expires, so an already existing header field will be overwritten.

The first directive sets the header field Cache-Control with the value max-age=290304000, that describes the freshness lifetime to be 290304000 seconds relative to the response time.

In contrast to that, the second directive sets the header field Expires with the value Thu, 15 Apr 2020 20:00:00 GMT that describes the freshness lifetime with an absolute time value.

Both Cache-Control’s max-age value and Expires expiration time stamp can be transformed to the other:

4.2.1. Calculating Freshness Lifetime

A cache can calculate the freshness lifetime (denoted as freshness_lifetime) of a response by using the first match of the following:

  • ...

  • If the max-age response directive (Section 5.2.2.8) is present, use its value, or

  • If the Expires response header field (Section 5.3) is present, use its value minus the value of the Date response header field, or

  • ...

But if both are present, Cache-Control’s max-age is preferred over Expires:

If a response includes a Cache-Control field with the max-age directive (Section 5.2.2.8), a recipient MUST ignore the Expires field. Likewise, if a response includes the s-maxage directive (Section 5.2.2.9), a shared cache recipient MUST ignore the Expires field. In both these cases, the value in Expires is only intended for recipients that have not yet implemented the Cache-Control field.

Instead of setting these HTTP caching control header fields manually, mod_expires ExpiresDefault directive allows an easy setup for HTTP caching. The freshness lifetime can either be described with an absolute value or with a relative value, either relative to the response time (i.e. access/now) or relative to the modification time of the requested file (i.e. modification). It uses both Cache-Control and Expires.

In this case the third directive sets the default freshness lifetime to be 10 years from the time of response on.

I would use mod_expires for HTTP cache control instead of doing it manually with Header. It is far more convenient, allows both relative and absolute freshness times and uses both Cache-Control and Expires.

这篇关于之间有三个的.htaccess到期规则差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆