打开 httpd.conf 取消注释

LoadModule expires_module modules/mod_expires.so

在文件后面追加

开启expire

<IfModule mod_expires.c>
    # 开启使用expires
    ExpiresActive on
 
    # css文件缓存7200000/3600/24=83天
    ExpiresByType text/css A7200000
 
    # js文件缓存83天
    ExpiresByType application/x-javascript A7200000
    ExpiresByType application/javascript A7200000
 
    # html文件缓存83天
    ExpiresByType text/html A7200000
 
    # 图片文件缓存83天
    ExpiresByType image/jpeg A7200000
    ExpiresByType image/gif A7200000
    ExpiresByType image/png A7200000
    ExpiresByType image/x-icon A7200000
 
    # 处理上述文件 其他都保存0秒(不保存)
    ExpiresDefault "now plus 0 min"
</IfModule>

在.htaccess文件后面追加

<IfModule mod_headers.c>
  # htm,html,txt类的文件缓存一个小时
  <FilesMatch "/.(html|htm|txt)$">
  header set cache-control "max-age=3600"
  </FilesMatch>
  # css, js, swf类的文件缓存一个星期
  <FilesMatch "/.(css|js|swf)$">
  header set cache-control "max-age=604800"
  </FilesMatch>
  # jpg,gif,jpeg,png,ico,flv,pdf等文件缓存一年
  <FilesMatch "/.(ico|gif|jpg|jpeg|png|flv|pdf)$">
  header set cache-control "max-age=29030400"
  </FilesMatch>
</IfModule>
最后修改:2023 年 03 月 06 日
如果觉得我的文章对你有用,请随意赞赏