Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 Redirect adding trailing slashes and encoding & as &

What I am trying to do is use an S3 bucket to perform http redirects via the "Static Web Hosting redirect requests".

The target bucket or domain that I'm trying to redirect to is: "example.com/test?param1=123&param2=456" and the protocol is "https".

When I use this setup though and hit my bucket it ends up redirecting me to: https://example.com/test?param1=123&param2=456/

Has anyone else worked through this?

like image 715
Aaron Osborne Avatar asked Jun 08 '18 15:06

Aaron Osborne


People also ask

Can we set TTL in S3?

If you want the same TTL for the whole S3 bucket served via Cloudfront, including newly added files, then you can set this in Cloudfront. Go to Cloudfront in the AWS console, click on Behaviours, click the distribution from this bucket, and click edit.

What is Subresources in S3?

Subresources. Amazon S3 uses the subresource mechanism to store object-specific additional information. Because subresources are subordinates to objects, they are always associated with some other entity such as an object or a bucket. For more information, see Object subresources. Access control information.

Can Cloudfront do redirects?

Short description. To redirect a domain in CloudFront, use one of the following: An Amazon Simple Storage Service (Amazon S3) website endpoint that returns a 301 status code. An edge function that redirects requests to the new domain.


1 Answers

Have seen the same and didn't want to do an html/js redirect - here's what I did:

Change the bucket to "use this bucket to host a website", put index.html as the index document but don't add an actual file, then in routing rules put this, replacing ampersands with &

<RoutingRules>
    <RoutingRule>
        <Redirect>
             <Protocol>https</Protocol> 
             <HostName>example.com</HostName>
             <ReplaceKeyWith>/test?param1=123&amp;param2=456</ReplaceKeyWith>
         </Redirect>
    </RoutingRule>
</RoutingRules>

Essentially, since no actual routing rule is specified this will reroute all traffic where you want. On save the & will be converted to & and no trailing slash will be added at the end.

like image 117
Ryan Avatar answered Sep 22 '22 07:09

Ryan