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년 전820회 조회
1개 답변
0

Well it seems I rubber ducked myself.

Of course there's the HostName property.

Which works a treat.

답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠