apache 设置图片等静态文件的过期时间

httpd.conf 中加入

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/gif  "access plus 1 days"
    ExpiresByType image/jpeg "access plus 24 hours"
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>

注释:
Expires 语法如下:
ExpiresByType type/encoding "<base> [plus] <num> <type>}*"

其中<base>是下列之一:
access
now (等价于'access')
modification

plus关键字是可选的。

<num>必须是整数,

<type>是下列之一:
years
months
weeks
days
hours
minutes
seconds


参考: http://apache.chinahtml.com/mod/mod_expires.html

添加新评论 »