Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

web config - IIS 7.5 How do you add a Dynamic HTTP Expires Header

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.

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.

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).

The header should look something like this:

Expires: Thu, 31 May 2012 10:59:25 GMT

How can I make it dynamically always show a date and time 7 days in the future?

Edit:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...