terry87
terry87

Reputation: 475

AWS Cloudfront and S3 redirects lose custom domain name

I have a S3 static website set up using CloudFront for HTTPS. I'm trying to add redirect rules, but I can't get it all to work together.

I have a Cloudfront distribution for www.mysite.com pointing at mysite.s3-website.us-east-2.amazonaws.com. This works great. It serves the default index page and custom error page. However, I now want to move page1 to page2. I tried setting up a redirect rule:

<RoutingRule>
  <Condition>
    <KeyPrefixEquals>page1</KeyPrefixEquals>
  </Condition>
  <Redirect>
    <ReplaceKeyWith>page2</ReplaceKeyWith>
  </Redirect>
</RoutingRule>

The redirect is triggered; however, it redirects away from mysite.com/page1 -> mysite.s3-website.us-east-2.amazonaws.com/page2!

Note: I can't use 301 redirect pages because some of the actual redirects are hash-related.

Any suggestions?

Upvotes: 1

Views: 568

Answers (1)

Kannaiyan
Kannaiyan

Reputation: 13055

I remember we had the following,

<RoutingRule>
  <Condition>
    <KeyPrefixEquals>page1</KeyPrefixEquals>
  </Condition>
  <Redirect>
    <HostName>www.mysite.com</HostName>
    <ReplaceKeyWith>page2</ReplaceKeyWith>
  </Redirect>
</RoutingRule>

Hope it helps.

Upvotes: 4

Related Questions