Apache配置mod_expires或mod_headers支持CACHE

发布于 2012-04-29 作者 [重庆SEO]

更新于 2015-10-16

mod_expires配置

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 days"
ExpiresByType text/html "access plus 1 weeks"
ExpiresByType image/gif "access plus 2 months"
ExpiresByType image/jpeg "access plus 2 months"
ExpiresByType application/x-shockwave-flash "access plus 2 months"
ExpiresByType application/x-javascript "access plus 2 months"
</IfModule>

mod_headers配置

<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(flv|gif|ico|jpeg)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# WEEK
<FilesMatch "\.(pdf|swf|js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# DAY
<FilesMatch "\.(htm|html|shtml)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
</IfModule>

mod_expires 和 mod_headers 只需要其中一种就可以了。