如何将缓存控制代码添加到htaccess? [英] How can i add cache control code to htaccess?

查看:60
本文介绍了如何将缓存控制代码添加到htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将缓存控制代码添加到.htaccess?

How can I add cache control code to .htaccess?

我的网站运行缓慢,我发现35个静态组件没有过期日期.

My site is slow and I found 35 static components without a far-future expiration date.

如何为此添加到期数据?我被告知可以在.htaccess文件中完成此操作,但我不知道如何操作.

How can I add expiration data for that? I was informed that this could be done in the .htaccess file but I don't know how.

推荐答案

您可以使用以下内容:

# Cache Files
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>

这会将所有以ico | pdf | flv | jpg .....结尾的文件缓存604800秒,即一周,您可以更改该编号以缓存所需的时间.

This caches any file ending with ico|pdf|flv|jpg..... for 604800 seconds, which is one week, you can change that number to cache for however long you feel you need.

这篇关于如何将缓存控制代码添加到htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆