.htaccess - 如何设置过期日期为过去?

发布于 2024-10-15 04:26:39 字数 248 浏览 11 评论 0原文

我注意到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夢归不見 2024-10-22 04:26:39

通过将 HTML 的过期时间设置为过去,我假设您正在尝试阻止 HTML 被缓存。不幸的是,您不能使用 Expires 指令,因为它只适用于将来的日期。不过,您可以使用标头命令来控制 HTML 文件的缓存方式。

<FilesMatch "\.(html|htm)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"
</FilesMatch>

需要在 Apache 中安装 mod_headers 模块才能使用此方法。

编辑:或者,如果您使用 PHP,则可以使用 PHP 的 header 函数设置这些标头。

header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");

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.

<FilesMatch "\.(html|htm)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"
</FilesMatch>

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.

header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文