1

我正在运行一个 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>
4

1 回答 1

2

你知道 /media 中有一个 htaccess 吗?(面部植物...)

如果您这样做,那么您可能需要考虑将“静态”内容放在一个单独的子域中,即无 cookie 的子域。

在 Magento 的后端转到 system->config->general->web 并输入http://static.yourdomain.com/

现在您可以将 .htaccess 指令移动到您的原始 httpd.conf 文件中(这在理论上更快)并删除/停放 .htaccess 文件。

现在将 cookie 域(在“会话 Cookie 管理”中)设置为 www.yourdomain.com - 现在 static.yourdomain.com 上不会有任何 cookie,因此 Web 服务器应该更快捷。如果这些图像没有通过,那么您可能需要在您的 DNS 'A' 记录上设置一个通配符,以便任何非 www 地址都通过同一个框。

您现在可以微调 /media 中的 .htaccess 文件,并将这些指令放入 static.yourdomain.com.conf

于 2012-08-29T13:41:32.627 回答