apache - .htaccess 缓存控制不缓存我的文件(js|png|css 等)

标签 apache .htaccess caching cache-control

正如我的标题所说,我正在尝试缓存控制我网站上的内容,但似乎我的内容没有被缓存。

这是我的 .htaccess 文件中的代码:

Header unset Pragma
FileETag None
Header unset ETag

# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
Header unset Last-Modified
</FilesMatch>

# cache html/htm/xml/txt diles for 2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

我尝试了很多教程,但似乎没有一个能奏效。
顺便说一句,其他 .htaccess 代码,如重定向和其他东西,确实有效。

最佳答案

我想通了,你必须删除 Header unset Last-Modified

Header unset Pragma
FileETag None
Header unset ETag

# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
</FilesMatch>

# cache html/htm/xml/txt files for 2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

关于apache - .htaccess 缓存控制不缓存我的文件(js|png|css 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12617174/

相关文章:

iphone - iPod/iPad 应用程序的存储限制是多少?

regex - 如何重定向完整域 URL 并使用 htaccess 删除子文件夹

php - 如何在Linux中设置权限/var/www以允许PHP-Apache自动覆盖

java - 构建 Apache 时未定义对 XML_GetErrorCode(和其他)的引用

django - Ubuntu 上的 Apache 错误 ERROR : Site (SiteName) does not exist

javascript - 有没有办法在没有 javascript 的情况下在移动应用程序上有一个完整的站点按钮?

.htaccess - 简单的 Htaccess 问题

java - 我应该在 Spring MVC Web 应用程序的 DAO 层或服务层上进行缓存吗?

c++ - 我可以检查缓存中是否有一 block 内存(例如,使用 malloc 分配)吗?

.htaccess - 从具有不同用户名的帐户引用 .htpasswd