添加没有 mod_expires 的过期标头?

发布于 2024-09-17 08:53:43 字数 100 浏览 2 评论 0原文

我知道我可以使用 mod_expires 添加过期标头。但是,如果 Apache 服务器没有安装 mod_expires 并且我不想通过 PHP 等脚本语言路由对文件的访问,我该怎么办?

I know that I can add expires header using mod_expires. However, what can I do if the Apache server doesn't have mod_expires installed and I don't want to route the access to the files through a scripting language like PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

尘曦 2024-09-24 08:53:44

您可以使用 mod_header 手动设置标头字段:

Header set Expires "..."

但是自从 过期 需要 绝对时间,使用缓存控制最大年龄 相对于访问时间的时间参数:

Header merge Cache-Control max-age=3600

You could use mod_header to set the header field manually:

Header set Expires "..."

But since Expires requires an absolute time, use Cache-Control’s max-age parameter for times relative to the access time:

Header merge Cache-Control max-age=3600
拥抱影子 2024-09-24 08:53:44

如果您有静态 Expires 标头,以下代码会将 Expires 标头添加到您的 js 和 css 文件中:

<FilesMatch "\.(js|css)$">
Header set Expires "Fri, 01 Jan 2010 00:00:00 GMT"
</FilesMatch>

If you have static Expires headers, the following will add an Expires header to your js and css files:

<FilesMatch "\.(js|css)$">
Header set Expires "Fri, 01 Jan 2010 00:00:00 GMT"
</FilesMatch>
幸福丶如此 2024-09-24 08:53:44

这应该告诉浏览器在后续访问时刷新页面。过期日期必须是过去的日期...您可以使用 PHP 设置日期,使其“只是”过去,或者将其保留为您找到此答案的日期!

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Thu, 2 Sep 2010 05:00:00 GMT");

更新:抱歉 - 我错过了有关通过 PHP 路由文件的句子中的“不要”!您还可以使用这些 HTML 元标记:

<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="Thu, 2 Sep 2010 05:00:00 GMT">

This should tell the browser to refresh the page on subsequent visits. The expires date just has to be in the past... you could set the date using PHP to make it "just" in the past, or just leave it as the date you found this answer!!!

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Thu, 2 Sep 2010 05:00:00 GMT");

UPDATE: Apologies - I missed the "Don't" in the sentence about routing files through PHP! You can also use these HTML meta tags:

<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="Thu, 2 Sep 2010 05:00:00 GMT">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文