【问题标题】:Cloudfront rewrite url to S3Cloudfront 将 url 重写为 S3
【发布时间】:2015-05-23 19:58:09
【问题描述】:

我有一个 Cloudfront 域,它以以下形式从 S3 提供图像:

http://static.example.com/images/image1.jpg -> S3://mybucket/images/image1.jpg

我需要重写,所以这个网址也可以:

http://static.example.com/this-is-example/images/image1.jpg -> S3://mybucket/images/image1.jpg

可以通过云端或其他亚马逊服务来做到这一点吗?

谢谢

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudfront


    【解决方案1】:

    由于您在 S3 之外提供服务,因此最好/最简单的做法是使用 S3 Routing Rules。这是一个应该捕获您要求的示例:

      <RoutingRules>
        <RoutingRule>
        <Condition>
          <KeyPrefixEquals>this-is-example/images/</KeyPrefixEquals>
        </Condition>
        <Redirect>
          <ReplaceKeyPrefixWith>images/</ReplaceKeyPrefixWith>
        </Redirect>
        </RoutingRule>
      </RoutingRules>
    

    这可能需要根据您的使用情况进行调整,但为此添加重定向/路由/重写规则应该相当容易。

    Note you can also add individual redirects with a different mechanism.

    【讨论】:

    • 谢谢,但我看到我无法为“this-is-example”部分添加通配符。此外,路由规则始终提供额外的 301 永久重定向。有没有办法放置通配符?正如我在文档中看到的,我认为 S3 路由规则是不可能的......
    • 它肯定会创建一个重定向。您的问题中根本没有提到通配符,并且无法进行重定向 - 完全匹配或前缀。 S3 用于静态内容和 URL,它不是完全可配置的 Web 服务器。 There's a strong argument to be made for S3 not being proper webserver at all,事实上。
    • 这种方法似乎适用于 s3,但我认为当内容由 cloudfront 提供时它不起作用。
    猜你喜欢
    • 1970-01-01
    • 2019-07-25
    • 2017-09-28
    • 2017-04-19
    • 2017-11-20
    • 2015-10-10
    • 1970-01-01
    • 2018-12-25
    • 2016-10-14
    相关资源
    最近更新 更多