I use some simple versioning system for my static files - I add 4 extra characters based on md5 of the file. Not all files can be versioned, so it gives me 2 cases:
/js/versioned_file.a32b.js => /js/versioned_file.js + Header(expire in 1year)
/js/unversioned_file.js => /js/unversioned_file.js (nothing changes, no extra headers)
For versioning I use (in vhost.conf):
RewriteRule ^(.*\.)[0-9a-f]{4}\.(css|jpg|gif|png|js|swf)$ /$1$2 [L]
It work very well.
Then to send extra headers just for versioned files:
<FilesMatch ^(.*\.)[0-9a-f]{4}\.(css|jpg|gif|png|js|swf)$>
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FileMatch>
This solution doesn't work because the rewrite rule changes ([L] makes a internal redirecting) the requested_uri, so the filematch is given the file name without the [0-9a-f]{4} part. I tryed to put filematch above rewriterule, but after the internal redirect (can i turn it off?) the headers are gone anyway.
So i thought I'll use environment variables, like so:
RewriteRule ^(.*\.)[0-9a-f]{4}\.(css|jpg|gif|png|js|swf)$ /$1$2 [L,E=OK:1]
Header set "Expires" "Mon, 28 Jul 2014 23:30:00 GMT" env=OK
Header set "Cache-Control" "max-age=315360000" env=OK
But this doesn't work because after the rewriterule sets OK=1, then it makes a internal redirect and (don't know why) the environment variable OK is gone
Any help is VERY MUCH APPRECIATED !!!
(sorry for any language mistakes)