S3 Static Website RoutingRules when using Cloudfront and a domain name

0

Hello, I'm having a problem with my S3 RoutingRules on an S3 static website.

I've got an S3 bucket dev.example.com set as static website hosting. I have a Cloudfront distribution using the bucket as an origin, via the s3-website URL (not the REST URL from the dropdown selection). My domain name is registered in R53 and pointed to the CloudFront distribution URL.

All of that is working very nicely.

However, I've been trying to add a 301 redirect from one bucket object to another - I moved a page on my website.

So I've got my S3 bucket RoutingRules as follows:

<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals>old-url</KeyPrefixEquals>
    </Condition>
    <Redirect>
      <ReplaceKeyPrefixWith>new-url</ReplaceKeyPrefixWith>
      <HttpRedirectCode>301</HttpRedirectCode>
    </Redirect>
  </RoutingRule>
</RoutingRules>

When I visit dev.example.com/old-url, the redirect takes place, but takes me to dev.example.com.s3-website.eu-west-2.amazonaws.com/new-url - not to my domain name.

Is it possible to tell S3 to redirect to the correct domain name?

I have tried adding the full URL to the new page, i.e. <ReplaceKeyPrefixWith>https://dev.example.com/new-url</ReplaceKeyPrefixWith>

  • but this doesn't work, I just get the S3 URL with my full URL on the end!

Suggestions gratefully received.

已提问 4 年前823 查看次数
1 回答
0

Well it seems I rubber ducked myself.

Of course there's the HostName property.

Which works a treat.

已回答 4 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则