Category Archives: auto-versioning

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

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?