的.htaccess:如何与QUOT;指定缓存验证及QUOT;? [英] .htaccess: How to "Specify a cache validator"?
问题描述
我在我的网站上运行谷歌PageSpeed和它的告诉我,我需要
指定缓存验证。
I'm running Google PageSpeed on my site and it's tell me that I need to
"Specify a cache validator."
以下资源缺少缓存验证。不指定缓存验证资源不能有效地刷新。指定一个Last-Modified或ETag头启用缓存验证以下资源:
The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources:
...然后列出图片,CSS,JS等。
... then it lists images, CSS, JS, etc.
据<一href="http://$c$c.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching">http://$c$c.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching:
设置Last-Modified日期,以最后一次资源被改变。如果Last-Modified日期足够远不够,在过去,很可能是浏览器不会重新读取它。
Set the Last-Modified date to the last time the resource was changed. If the Last-Modified date is sufficiently far enough in the past, chances are the browser won't refetch it.
我在我的.htaccess如下:
I have the following in my .htaccess:
<IfModule mod_headers.c>
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
Header set Last-Modified "Tue, 31 Aug 2010 00:00:00 GMT"
</FilesMatch>
</IfModule>
我是什么做错了吗?
What am I doing wrong?
推荐答案
我想你遇到的问题是过期:
而不是上次修改:
。阿帕奇将在默认情况下发送的文件的Last-Modified:基于文件的日期
头。我建议拆除上部code和具有以下替换它:
I think the problem you are having is with Expire:
and not with Last-Modified:
. Apache would by default send the file Last-Modified:
header based on the file date. I suggest removing the upper code and replacing it with the following:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 year"
</IfModule>
尝试使用,如果它没有工作,尝试添加这个问题,以及:
Try with that, if it didn't work try adding this as well:
<IfModule mod_headers.c>
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"
</FilesMatch>
</IfModule>
这篇关于的.htaccess:如何与QUOT;指定缓存验证及QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!