为特定图像添加过期标头
我看过的所有过期标题文章或多或少都提供了以下解决方案:
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
但这对我来说没有意义,因为我知道哪些图像会改变,哪些不会改变,所以我想能够将特定的到期日期添加到特定的图像文件。我该怎么办呢?
All of the expires headers articles I've looked at give more or less the following solution:
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
But it doesn't make sense to me because I know which of my images are going to change and which aren't, so I want to be able to add specific expiration dates to specific image files. How would I go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
FilesMatch
,例如。或者对于某些特定文件:
You can use a
FilesMatch
, eg.Or for some specific files:
请注意,如果您已经使用了
ExpiresByType
,则对特定文件使用ExpiresDefault
将不起作用。您需要再次使用ExpiresByType
。所以这不起作用(
service-worker.js
仍然有 +1 年的有效期):但这会起作用(
service-worker.js
将有 +0 秒的有效期):您还可以使用
Header unset Expires
。无论上面设置了什么,这都会删除Expires
标头。您还应该修改(或删除)Cache-Control
标头。看来 mod_expires 两者都设置了。Note that using
ExpiresDefault
for specific files will not work if you already usedExpiresByType
. You need to useExpiresByType
again.So this will NOT work (
service-worker.js
would still have +1 year expiry):But this will work (
service-worker.js
will have +0 seconds expiry):You might also use
Header unset Expires
. This would removeExpires
header no matter what was set above it. You should also modify (or remove)Cache-Control
header. It seems thatmod_expires
sets both.