Cloudfront将URL重写为S3 [英] Cloudfront rewrite url to S3
问题描述
我有一个Cloudfront域,该域以以下形式存储来自S3的图像:
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
http://static.example.com/images/image1.jpg -> S3://mybucket/images/image1.jpg
我需要进行重写,因此该URL也可以正常工作:
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
http://static.example.com/this-is-example/images/image1.jpg -> S3://mybucket/images/image1.jpg
是否可以使用cloudfront或其他亚马逊服务?
It's possible to do this with cloudfront or another amazon service ?
谢谢
推荐答案
由于您正在使用S3,因此最好/最简单的方法是使用 S3路由规则 。这是一个示例,可以捕获您的要求:
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.
这篇关于Cloudfront将URL重写为S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!