S3 redirect loses query string
See original GitHub issueHi, I’m having the following issue:
Say I have a page called nice-page
. Currently, whenever I access a url without a forward slash at the end of its path, e.g.:
https://mywebsite.com/nice-page
S3 tries to find an object with that name (nice-page
) but instead finds nothing, so it falls back to trying to find a folder with that name, therefore sending a 302 to the client and redirecting it to
https://mywebsite.com/nice-page/
(notice the forward slash at the end). This opens the page correctly, however, when the redirect happens, the browser loses all query string parameters, making we lose campaign traffic informations like utm_source
, utm_campaign
etc.
Do you guys have any idea of how to fix this?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Amazon S3 Redirect Rule - Preserve Query Params
The problem was that I had the origin set up in CloudFront not to forward Query Strings so when S3 got the request...
Read more >S3 redirect to another domain and preserving Query String
The issue of losing the campaign query strings during the redirect is because of the element ReplaceKeyWith .
Read more >Amazon S3 Bucket Redirect with Query Params - Tushar Ghate
Using an Amazon S3 Bucket to redirect to a URL with query parameters.
Read more >Values that you specify when you create or update a distribution
Query string whitelist (Applies only when you choose Forward all, cache based on ... Redirect response from Amazon S3? and Temporary Request Redirection....
Read more >Querystring parameters - HTTPie 3.2.1 (latest) docs
The initial URL is always used as the basis for the generated filename — even if there has been one or more redirects....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@philippeehlert While testing my new terraform-aws-gatsby module I wrote a Lambda@Edge function which I believe achieves what you want. Attach this function to the Origin Response event:
You will need to ensure that on your CF distribution, “Query String Forwarding and Caching is set either to Forward All, Cache Based on Whitelist or to Forward All, Cache Based on All” as mentioned here.
This lambda function will preserve the query string for all 3XX responses. If you want to be more selective, you will have to modify the function.
@JoshuaWalsh: What needs to be done to get the “301” in your code?