如何使用 htaccess 将图像在我的网站上缓存 2 天,以便:
1 x 60 x 60 x 24 x 2 = 172800s
所以我想缓存'png,jpeg,jpg,ico,js'。我怎样才能用 htaccess 做到这一点
如何使用 htaccess 将图像在我的网站上缓存 2 天,以便:
1 x 60 x 60 x 24 x 2 = 172800s
所以我想缓存'png,jpeg,jpg,ico,js'。我怎样才能用 htaccess 做到这一点
您可以使用该mod_expires
模块(基于文件的 MIME 类型):
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300
# png, jpeg, jpg, ico, js expire after 2 days
ExpiresByType image/gif A172800
ExpiresByType image/png A172800
ExpiresByType image/jpg A172800
ExpiresByType image/x-icon A172800
ExpiresByType application/x-javascript A172800
</ifModule>
或mod_headers
模块(基于文件扩展名):
<ifModule mod_headers.c>
ExpiresActive On
# png, jpeg, jpg, ico, js expire after 2 days
<filesMatch ".(gif|png|jpg|jpeg|ico|js)$">
Header set Cache-Control "max-age=172800"
</filesMatch>
</ifModule>
最后一个为您提供了更多选项,例如强制无缓存等。