Magento and Apache - Cache settings seem to be ign

2019-06-04 05:32发布

I'm running an instance of Magento and I'm trying to set the caching rules for the content that is not going to change often. I added the rules I wanted to the .htaccess file (rules are at the bottom of the post) which is located in Magento root folder, but they seem to be ignored. When I check the http headers, this is what I see:

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

Obviously, I'm doing something wrong here. Is there anything I should check to see who is forcing a "no-cache" policy, and where? Thanks in advance for the answers.

Rules added to .htaccess file

# 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>

1条回答
该账号已被封号
2楼-- · 2019-06-04 06:03

You did know there is a htaccess in /media? (Faceplant...)

If you are doing this then you may want to consider putting the 'static' content on a separate sub domain, one that is cookie free.

In the backend of Magento go to system->config->general->web and enter http://static.yourdomain.com/

Now you can move the .htaccess directives into your original httpd.conf file (this is notionally quicker) and remove/park the .htaccess file.

Now set the cookie domain (in 'Session Cookie Management') to www.yourdomain.com - now there won't be any cookies on static.yourdomain.com so the web server should be snappier. If those images are not coming through then you may need to setup a wildcard on your DNS 'A' record so that any non-www address goes through to the same box.

You can now fine-tune the .htaccess file in /media and put those directives in the static.yourdomain.com.conf

查看更多
登录 后发表回答