我正在运行一个 Magento 实例,并且正在尝试为不会经常更改的内容设置缓存规则。我将我想要的规则添加到位于 Magento 根文件夹中的 .htaccess 文件(规则在帖子的底部),但它们似乎被忽略了。当我检查 http 标头时,这就是我所看到的:
Pragma: no-cache, no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private, no-cache, no-store, proxy-revalidate, no-transform
显然,我在这里做错了什么。有什么我应该检查的,看看谁在强制执行“无缓存”策略,在哪里?提前感谢您的答案。
添加到 .htaccess 文件的规则
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
# Set up caching on media files for 2 weeks
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A1209600
Header append Cache-Control "public"
</FilesMatch>
# Set up 1 week caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A604800
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>