Skip to content

Instantly share code, notes, and snippets.

@cam8001
Created November 1, 2020 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cam8001/4fab14cb2ee2c7b77fa8cbd65085c905 to your computer and use it in GitHub Desktop.
Save cam8001/4fab14cb2ee2c7b77fa8cbd65085c905 to your computer and use it in GitHub Desktop.
Redirect entire s3 bucket

You can use s3 redirection rules to setup redirects.

For example, you might want to redirect one easy to remember domain to some tricky URL.

Create an empty bucket, point your domain to it, then create a rule that catches 404 Not Found and redirects it wherever you need.

New console

[
  {
    "Condition": {
      "HttpErrorCodeReturnedEquals": "404"
    },
    "Redirect": {
      "Protocol": "https",
      "HostName": "example.com",
      "ReplaceKeyPrefixWith": "/my-long/url/2020/yes.html",
      "HttpRedirectCode": "302"
    }
  }
]

Old console

<RoutingRules>
  <RoutingRule>
    <Condition>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <Protocol>https</Protocol>
      <HostName>example.com</HostName>
      <ReplaceKeyPrefixWith>/my-long/url/2020/yes.html</ReplaceKeyPrefixWith>
      <HttpRedirectCode>302</HttpRedirectCode>
    </Redirect>
  </RoutingRule>
</RoutingRules>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment