Cloudfront rewrite url to S3

橙三吉。 提交于 2019-12-07 11:55:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!