htaccess的缓存与FilesMatch [英] .htaccess caching with FilesMatch

查看:303
本文介绍了htaccess的缓存与FilesMatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让浏览器缓存与htaccess文件。

I need to make browser caching with htaccess file.

从<一个href="http://stackoverflow.com/questions/6724549/caching-and-gzip-com$p$pssion-by-htaccess/6724556#6724556">this问题我发现了如何扩展添加到htaccess文件。

From this question I found out how to add extensions to htaccess file.

<FilesMatch "\.(js|jpeg|jpg)$">

但我需要添加扩展。但排除某些文件。
我发现像这样的<一个href="http://stackoverflow.com/questions/2182936/htaccess-deny-access-to-specific-files-more-than-one/2183013#2183013">this问题

But I need to add extensions. But exclude some of the files.
I found something like this from this question

<FilesMatch ^((myfile|myfile2)\.js$|myphoto\.jpe?g)$>

添加所有的JS和JPEG文件,除了myfile.js,myfile2.js,myphoto.jpg 我怎样才能做到这一点? 谢谢

Add all js and jpeg files except "myfile.js", "myfile2.js", "myphoto.jpg" How can I do this? Thank you

推荐答案

试试这个

<FilesMatch "((?<!myfile|myfile2)\.js|(?<!myphoto).jpe?g)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>

这将匹配所有的 JS JPEG 除了 myfile.js myfile2.js myphoto.jpeg 使用负向前查找/后向。有点难看,但我无法找到一个很好的方法来做到这一点。

This will match all js and jpeg files except myfile.js, myfile2.js, and myphoto.jpeg using negative lookahead/lookbehind. Kind of ugly but I couldn't find a nice way to do this.

您可以再有一个单独的文件中匹配的只有的这些文件,并设置不同的页眉:

You can then have a separate files match for only those files and set a different header:

<FilesMatch "((myfile|myfile2)\.js|myphoto\.jpe?g)$">
    Header set Cache-Control "max-age=3600, public" 
</FilesMatch>

这篇关于htaccess的缓存与FilesMatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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