Enabling mod_expire depending on the request

Instead of generating links to file.js , I calculate the version number or hash amount and bind to file--bbe02f946d.js . I use the following redirection rule to then serve the current version of the file:

 RewriteRule ^(.*)--[a-z0-9]+\.js$ $1.js 

Now I want to set very far Expires headers for these requests:

 ExpiresActive on ExpiresByType application/javascript "access plus 1 year" 

This works fine, but it also applies to non-versioned resources ( /file.js requests). How to set expires header only for requests matching RewriteRule? I usually use <LocationMatch> , but this is not possible, since the application should work on arbitrary servers, where I can just change htaccess.

+4
source share
1 answer

You can add a new mime type with htaccess and set custom expiration headers.

.Xjs example

 <IfModule mod_mime.c> AddType application/x-javascript .xjs </IfModule> <IfModule mod_gzip.c> mod_gzip_item_include file \.xjs$ </IfModule> <FilesMatch ".(xjs)$"> Header set Cache-Control "max-age=43200" </FilesMatch> 

or just use regex in FilesMatch to match your js file

 <FilesMatch "--[a-z0-9]+\.js$"> Header set Cache-Control "max-age=43200" </FilesMatch> 
0
source

All Articles