Reputation: 1
I am serving static content with Amazon CloudFront and am using my servers as the origin.
Since CF does not respect ? query strings, I can't easily force CF to use new versions of .png files. I also need fast invalidation and do not want to pay for invalidation requests.
So I want to create a completely fake directory with .htaccess to force versioning for my images.
For instance, I want:
domain.com/static/0.12/images/background.png
going to
domain.com/static/images/background.png
Where 0.12 is my APP version, which will be automatically changed through my deployment script.
What would be the .htaccess rule for this?
Upvotes: 0
Views: 2690
Reputation: 9539
If you actually want the URL
domain.com/static/0.12/images/background.png
to be internally redirected to
domain.com/static/images/background.png
Add the following to the .htaccess file in the root of your site.
RewriteEngine On
RewriteBase /
RewriteRule ^static/0\.12/images/(.+)$ static/images/$1 [L,NC]
If the APP version varies then use
RewriteEngine On
RewriteBase /
RewriteRule ^static/[\.0-9]+/images/(.+)$ static/images/$1 [L,NC]
Upvotes: 1
Reputation: 270677
To force all requests from a URL like
example.com/static/images/background.png
to rewrite to internal URLs like
example.com/static/0.12/images/background.png
Use:
RewriteEngine On
RewriteRule ^static/images/(.*)$ static/0.12/images/$1 [L]
Upvotes: 0