Reputation: 31
To help control caching on our site I'm looking to name some of the resource files (css & js) with a version number in their url (eg. site.v104.css) which will allow us to push updates through to users when we want, but to reduce maintenance and renaming the actual file each time I want to setup a .htaccess rule which will automatically rewrite these urls from the browser and present the content from its actual location.
If the file is in the css folder and ends with .vNNN.css then I want to server up the content from .vNNN, so for example if the file in the HTML of the site is: "site_media/css/site.v104.css" then I want it to load the content from "site_media/css/site.css" and the below rule works for this.
In my .htaccess file I have added the following line:
RewriteRule ^(site_media/css/.*).v\d+(\.css) /$1$2 [U,L]
However if I have a file with multiple '.' (eg. "site_media/css/site.prod.v104.css") then it doesn't work it returns "site_media/css/site.css" instead of "site_media/css/site.prod.css".
I could live without checking that the file is in the correct folder but I want to be safe and control exactly which ones it replaces.
Upvotes: 1
Views: 84
Reputation: 31
Fixed - found that the bug with the lookahead was causing it to not work (and that half my issue was the regex tester I was using). The code above does work.
Upvotes: 1