Source url prefix appended to destination url when using CloudFront and S3 AWS

0

I am trying to redirect a url, example.io, to www.example.org/survey/imagine.

Currently, my S3 bucket handles redirection with the following redirection rules:

<RoutingRules> <RoutingRule> <Condition> <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> </Condition> <Redirect> <HostName>www.example.org</HostName> <ReplaceKeyPrefixWith>survey/imagine</ReplaceKeyPrefixWith> </Redirect> </RoutingRule> <RoutingRule> <Condition> <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals> </Condition> <Redirect> <HostName>www.example.org</HostName> <ReplaceKeyPrefixWith>survey/imagine</ReplaceKeyPrefixWith> </Redirect> </RoutingRule> </RoutingRules>

My issue is when I add any prefix to example.io, that prefix is appended to the url of the destination.

Examples:

example.io/something redirects to www.example.org/survey/imaginesomething

example.io/blah redirects to www.example.org/survey/imagineblah

example.io/blah/there redirects to www.example.org/survey/imagineblah/there

Desired Result:

example.io/something redirects to www.example.org/survey/imagine

example.io/blah redirects to www.example.org/survey/imagine

example.io/blah/there redirects to www.example.org/survey/imagine

I am using CloudFront to handle the DNS services and distribution of example.io. In CloudFront for example.io, I have an invalidation with the object path /*. I have a behavior with path pattern /*, which should redirect all requests for example.io/*, where * is a wildcard, to the example.io s3 bucket endpoint.

Adam Tapp

Posted 2019-07-09T14:56:27.043

Reputation: 1

Answers

0

<ReplaceKeyPrefixWith> removes the matched key prefix and prepends the new value to the path, after the leading slash.

Since you aren't specifying a key prefix to match, it replaces the "first zero bytes" with the specified string.

If you want to redirect to /survey/imagine no matter what path is specified, change this to <ReplaceKeyWith>survey/imagine</ReplaceKeyWith> which replaces everything, discarding the original path.

Michael - sqlbot

Posted 2019-07-09T14:56:27.043

Reputation: 1 103