.Htaccess caching using FilesMatch

I need to do browser caching with an htaccess file.

From this question, I learned how to add extensions to the htaccess file.

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

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)$> 

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

+3
regex caching browser-cache .htaccess
source share
1 answer

try it

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

This will match all js and jpeg files except myfile.js , myfile2.js and myphoto.jpeg using a negative lookahead / lookbehind. The view is ugly, but I could not find a good way to do this.

Then you can map individual files only for these files and set a different header:

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

All Articles