我正在运行Magento的一个实例,我正在尝试为不会经常更改的内容设置缓存规则。我在.htaccess文件中添加了我想要的规则(规则位于帖子的底部),它位于Magento根文件夹中,但它们似乎被忽略了。当我检查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>
答案 0 :(得分:2)
您确实知道/媒体中有htaccess吗? (Faceplant ...)
如果您这样做,那么您可能需要考虑将“静态”内容放在一个单独的子域上,一个不含cookie的子域。
在Magento的后端转到system-&gt; config-&gt; general-&gt; web并输入http://static.yourdomain.com/
现在您可以将.htaccess指令移动到原始httpd.conf文件中(这在概念上更快)并删除/停放.htaccess文件。
现在将cookie域(在'Session Cookie Management'中)设置为www.yourdomain.com - 现在static.yourdomain.com上没有任何cookie,因此Web服务器应该更快捷。如果这些图像没有通过,那么您可能需要在DNS“A”记录上设置通配符,以便任何非www地址都可以进入同一个框。
您现在可以微调/ media中的.htaccess文件,并将这些指令放在static.yourdomain.com.conf中