IIS 7.5 如何添加动态 HTTP 过期标头 [英] IIS 7.5 How do you add a Dynamic HTTP Expires Header
问题描述
在 IIS 7.5 中,您可以添加静态 HTTP 响应标头,但我想添加一个过期"标头,该标头始终指定未来 7 天的日期.
In IIS 7.5, you can add static HTTP Response headers, but I want to add an "Expires" header that always specifies a date that is 7 days in the future.
我正在运行 php 5.4,所以我想要一个解决方案,它可以通过编辑 web.config 文件而不是一些 c# 代码解决方案来做到这一点.
I'm running php 5.4, so I'd like a solution that can do this by editing the web.config file rather than some c# code solution.
我知道如何使用 php 添加标题,但这对静态图像文件的 http 标题(jpg、gif、png 等)没有帮助.
I know how to add the header using php, but that won't help for static image file's http headers (jpg, gif, png, etc).
标题应该是这样的:
到期:格林威治标准时间 2012 年 5 月 31 日星期四 10:59:25
Expires: Thu, 31 May 2012 10:59:25 GMT
如何让它动态显示未来 7 天的日期和时间?
How can I make it dynamically always show a date and time 7 days in the future?
请注意,我的 php 文件中有我想要的 expires 标头:
Notice that I have the expires header that I want on my php files:
http://web-sniffer.net/?url=http%3A%2F%2Fwww.bestds.com
但是,我无法为 png 文件上的到期"键指定一个提前 7 天的日期(例如),我必须在未来使用一个静态日期:
However, I'm not able to specify a date that is 7 days ahead for the "Expires" key on png files (for example), I'm having to use a static date far in the future:
http://web-sniffer.net/?url=http%3A%2F%2Fwww.bestds.com%2Fimage%2Ftlogo.png
推荐答案
这是 IIS 的标准功能.HTTP Response Headers 模块允许您设置此通用标头.这将导致以下 web.config:
This is a standard feature of IIS. The HTTP Response Headers module allows you to set this common header. This results in the following web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
您应该只在要发送此标头的目录中执行此操作.通常只有包含静态内容的目录.
You should do this only in the directories where you want this header to be send. Typically only directories with static content.
这篇关于IIS 7.5 如何添加动态 HTTP 过期标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!