Chris Deal
Chris Deal

Reputation: 58

AWS Route 53 / S3 Bucket Redirect All to One URL

I'm trying to do the following with AWS Route 53 and S3 based on some other articles I've found:

oldsite.com/* to newsite.com/page

I'd like to redirect all of oldsite.com and any path to the single url of newsite.com/page.

Both of the articles below are close, but they give me the following:

oldsite.com/* to newsite.com/page/*, which will likely result in newsite.com/404

For further clarification:

I don't want oldsite.com/foo to redirect to newsite.com/page/foo

I want oldsite.com/foo to redirect to newsite.com/page

Referenced articles that are giving me to the /* to /* instead of /* to /static.

Set up DNS based URL forwarding in Amazon Route53

http://www.holovaty.com/writing/aws-domain-redirection/

Upvotes: 1

Views: 1697

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

Don't explicitly configure the bucket to redirect all requests to another host.

Configure the bucket for static web site hosting, then create a routing rule that matches 403 Forbidden (since S3 denies everything by default) and points where you want things to go.

<RoutingRules>
 <RoutingRule>
  <Condition>
    <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
  </Condition>
  <Redirect>
   <HostName>target.example.com</HostName>
   <ReplaceKeyWith>static</ReplaceKeyWith>
  </Redirect>
 </RoutingRule>
</RoutingRules>

All requests should redirect to http://target.example.com/static.

Note that the leading slash is omitted for <ReplaceKeyWith>.

Upvotes: 1

Related Questions