Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

According to the apache FilesMatch docs:

The FilesMatch directive provides for access control by filename

Basically, I only want to set an expires header for resources that have a 10 digit "cache buster" id appended to the name. So, here is my attempt at such a thing in my httpd.conf

<FilesMatch "(jpg|jpeg|png|gif|js|css)\?\d{10}$">
    ExpiresActive On
    ExpiresDefault "now plus 5 minutes"
</FilesMatch>

And here is an example of a resource I want to match:

http://localhost:3000/images/of/elvis/eating-a-bacon-sandwich.png?1306277384

Now obviously my FilesMatch regexp is not matching so I am guessing 1 of 2 things is happening. Either my regexp is wonky or the '?1231231231' cache busting part of the file is not part of what apache considers part of the filename. Can anybody confirm and/or give me a way to cache only those resources that will not persist beyond the next deploy?

share|improve this question
add comment

migrated from stackoverflow.com Jun 30 '11 at 17:39

This question came from our site for professional and enthusiast programmers.

2 Answers

I've just been wrestling with an htaccess problem with a ? in the URL. The ? is not technically part of the filename, but a query string. I wouldn't be surprised if it doesn't get passed to FilesMatch.

The thing that I used was

RewriteCond %{QUERY_STRING} ^something$

Obviously you're not doing rewriting, but you could try and trap the %{QUERY_STRING}.

share|improve this answer
add comment

Ran a simple test and I think I have the answer.

Resource name: http://localhost:3000/stylesheets/baseline.css?1309365344

First Test -- Failed -- This did not cache the baseline.css file

<FilesMatch "baseline.css\?1309365344">
    ExpiresActive On
    ExpiresDefault "now plus 1 week"
</FilesMatch>

Second Test -- Success -- This did cache the baseline.css file

<FilesMatch "baseline.css">
    ExpiresActive On
    ExpiresDefault "now plus 1 week"
</FilesMatch>

Conclusion: When apache says "FilesMatch directive provides for access control by filename", they do not include anything after the extension as part of the filename.

However, I still need to find a way to only apply the ExpiresDefault to resources that has a timestamp on the resource path; I'll put that in another question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.