为什么我的服务器总是返回最后修改作为我的当前时间


Why is my server always returns Last Modified as my current time?

所以将我的vhost.conf文件设置为Expires:

ExpiresActive On
ExpiresDefault "access plus 4 hours"
ExpiresByType application/javascript "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/xml "access plus 1 hour"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/plain "access plus 1 hour"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpg "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType image/bmp "access plus 10 years"
ExpiresByType application/x-shockwave-flash "access plus 10 years"

我认为它是工作的,因为响应头返回一个缓存控制设置到未来:

Cache-Control   max-age=315360000
Expires Sun, 04 Apr 2021 12:27:12 GMT

但是我看了看Firefox的缓存选项卡,它看起来不太好

Last Modified   Thu Apr 07 2011 20:27:08 GMT+0800 (Malay Peninsula Standard Time)
Last Fetched    Thu Apr 07 2011 20:27:09 GMT+0800 (Malay Peninsula Standard Time)
Expires      Sun Apr 04 2021 20:27:07 GMT+0800 (Malay Peninsula Standard Time)

是这样的。每次我重新加载我的网站,最后修改头总是设置为我的当前时间。我没有修改文件,所以为什么它返回我的当前时间?

这是一个PHP脚本,其输出是在运行脚本时生成的,因此该输出以前从未存在过,这意味着服务器无法将缓存头附加到它。

您需要自己设置header()呼叫的最后修改时间。