Reputation: 33996
I need to make browser caching with htaccess file.
From this question I found out how to add extensions to 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? Thank you
Upvotes: 4
Views: 4418
Reputation: 143856
Try this
<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 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>
Upvotes: 3