问题
I have a Cloudfront domain that servers images from S3 in the form:
http://static.example.com/images/image1.jpg -> S3://mybucket/images/image1.jpg
I need to do a rewrite, so this url works as well:
http://static.example.com/this-is-example/images/image1.jpg -> S3://mybucket/images/image1.jpg
It's possible to do this with cloudfront or another amazon service ?
Thanks
回答1:
Since you are serving out of S3, the best/easiest thing to do is to use S3 Routing Rules. Here's an example that should capture what you asked for:
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>this-is-example/images/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>images/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
This may need tuning depending on your usage, but it should be fairly easy to add redirect/routing/rewrite rules for this.
Note you can also add individual redirects with a different mechanism.
来源:https://stackoverflow.com/questions/29166016/cloudfront-rewrite-url-to-s3