1

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/

Community
  • 1
  • 1
Chris Deal
  • 48
  • 6

1 Answers1

1

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>.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • That worked great, thanks! One small correction though, you're missing the closing element on . Needs the – Chris Deal Aug 17 '16 at 20:22
  • @ChrisDeal thanks. Fixed. Writing XML on an android phone keyboard... not recommended. :) – Michael - sqlbot Aug 17 '16 at 20:33
  • @Michael-sqlbot, it works perfectly fine!! Thanks! But why is the 403 condition necessary? Did not understand that completely. – Yahya Sep 22 '16 at 13:01
  • @Yahya thanks. The reason for 403 is that when you access a page anonymously, you don't have **permission to discover** whether (a) the object exists but you lack permission to view it, or (b) the object doesn't exist. If "object present but unauthorized" was `403 Forbidden` and "object absent" was `404 Not Found`, that could arguably reveal too much information to a malicious user. If you give "Everyone" permission to list the bucket, then the error would indeed be 404, and you'd need a rule for that, but it seems like a rare occurrence where you'd want just anybody to list your objects. – Michael - sqlbot Sep 22 '16 at 13:34