虚拟主机技术

伏笔主机网站空间通过 .htaccess 设置静态资源缓存加速网

2019-03-25  本文已影响0人  9d24c0c9a612

在每个网站的 根目录 .htaccess 文件里 加入 以下内容

RewriteEngine on

# 1 Month for all your static assets 一个月

 <FilesMatch ".(ico|pdf|bmp|vbs|flv|jpg|jpeg|png|gif|js|css|swf)$">

 Header set Cache-Control "max-age=2592000, public"

 </FilesMatch>

 # 1 DAYS for rss feeds and robots  一天

 <FilesMatch ".(xml|txt)$">

 Header set Cache-Control "max-age=86400, public, must-revalidate>

 </FilesMatch>

 # 8 HOURS for your real articles files 8小时

 <FilesMatch ".(html|htm)$">

 Header set Cache-Control "max-age=28800, must-revalidate>

 </FilesMatch>

过期时间 是用秒来记录的. 这样 APACHE 服务器就会告诉你的浏览器 资源还没过期不需要重新下载 而是尽可能的去本地找之前已经缓存好的, 这样一是减少服务器负担 另一是加快页面读取时间.

上一篇 下一篇

猜你喜欢

热点阅读