Issue with htaccess redirect for static file versioning not working with .min file names

136 Views Asked by At

I am trying to implement file versioning with php and htaccess for cache busting purposes. I had a good rewrite in htaccess that seemed to work well, but does not work when I have .min in the file name. I need the rewrite to account for situations with .min or without .min.

For example, I need style.1456594559.css to redirect to style.css and I need style.min.1456594559.css to redirect to style.min.css.

Here is the regex I currently have:

RewriteRule ^(scripts|css)/(.+)\.(.+)\.(js|css)$ $1/$2.$4 [L]

This strips out the .min when that is present in the file name. Is there a solution that accounts for both, or does it need to be two different rewrites?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use this rule:

RewriteRule ^(scripts|css)/(.+)\.\d+\.(js|css)$ $1/$2.$3 [L,NC]