Apache:ExpiresDefault 不起作用,而“Header”不起作用做。怎么来的?
如果我这样做:
<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|css|js|php)$">
ExpiresActive On
ExpiresDefault "access plus 30 days"
</FilesMatch>
</IfModule>
它没有正确设置过期标头,而如果我像这样手动“强制”它:
<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|css|js|php)$">
ExpiresActive On
Header set Expires "Thu, 18 Jan 2012 20:00:00 GMT"
</FilesMatch>
</IfModule>
它可以工作。这意味着两件事:
- mod_expire 已安装(
IfModule mod_expires.c
为 true), - 应用此规则后,Expire 标头不会被修改。
我缺少什么?
顺便说一句:如果你有任何解决方案让它发挥作用,我就是你的人!
If I do this:
<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|css|js|php)$">
ExpiresActive On
ExpiresDefault "access plus 30 days"
</FilesMatch>
</IfModule>
It doesn't set properly the Expire header, whereas if I "force" it by hand like this:
<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|css|js|php)$">
ExpiresActive On
Header set Expires "Thu, 18 Jan 2012 20:00:00 GMT"
</FilesMatch>
</IfModule>
It works. This implies 2 things:
- mod_expire is installed (
IfModule mod_expires.c
is true) - the Expire header is not modified after this rule is applied.
What am I missing?
By the way: if you have any solution to make it work I'm your man!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我从官方文档这里得到了它:
因此它仅适用于静态文件,不适用于所有其他文件:它们不是静态的。
Ok I've got it from the official documentation here:
So it works only for static files, and not for all the other ones: they're not static.
这也让我难住了,因为据我所知,它应该可以工作,所以我在一个测试虚拟机上尝试了它,改变了 N 天并刷新了它。对我来说效果很好。我的 Apache 版本是
任何测试文件的标头(使用 chrome 开发人员工具)(N=15)显示:
我的想法是任何
ExpiresDefault
都可以被Header set Expires< /代码>。您是否已对
.htaccess
层次结构进行了 grep,以确保您的ExpiresDefault
不会在较低级别被覆盖。如果您不希望 htaccess 文件执行此操作,则需要在 http 配置中禁用它们。
This one got me stumped as well because AFAIK, it should work so I tried it on a test VM varying the N days and refreshing. Works fine for me. My Apache version is
Any the headers for a test file (using chrome developer tools) (with N=15) show:
My thought is that any
ExpiresDefault
can be overridden by aHeader set Expires
. Have you grepped the.htaccess
hierarchy to make sure that yourExpiresDefault
isn't being overridden at a lower level.If you don't want htaccess files doing this you need to disable them in your http config.