.htaccess - 如何设置过期日期为过去?
我注意到 Google 将其 HTML 的过期日期设置为过去的日期:
Expires Thu Jan 01 1970 00:00:00
How do I configure .htaccess to do this?我使用 ExpiresByType
来设置其他资源的过期时间,但它们都是未来的时间(例如访问加 10 年
)。关于如何设置过去有什么建议吗?谢谢。
I noticed that Google sets the expiration of its HTML to a date in the past:
Expires Thu Jan 01 1970 00:00:00
How do I configure .htaccess to do this? I use ExpiresByType
to set the expiration of my other resources, but they are all future times (e.g. access plus 10 years
). Any suggestions on how to set it for the past? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将 HTML 的过期时间设置为过去,我假设您正在尝试阻止 HTML 被缓存。不幸的是,您不能使用 Expires 指令,因为它只适用于将来的日期。不过,您可以使用标头命令来控制 HTML 文件的缓存方式。
需要在 Apache 中安装 mod_headers 模块才能使用此方法。
编辑:或者,如果您使用 PHP,则可以使用 PHP 的
header
函数设置这些标头。By setting the expiration of the HTML to the past, I'm assuming you're trying to prevent your HTML from being cached. Unfortunately, you cannot use the Expires directive as it only works for future dates. You can use header commands though to control how your HTML files are cached.
The
mod_headers
module will need to be installed in Apache to use this method.EDIT: Alternatively, if you're using PHP, you can set these headers using PHP's
header
function.