Rewrite URLs for an S3 hosted site

0

I'm currently hosting a React site on S3 with CloudFront. One of the URLs used currently looks like this: https://example.org/submit/${token}. As token varies in length, it sometimes means that the total URL can be longer than the S3 limit of 1024. To get around this I'd like to change to a new URL system so that the same route is now located at https://example.org/submit?token=${token} (I assume the query string doesn't count towards the key length limit). This is easy enough to do but I'd like to maintain backwards compatibility with the old route format.

Is there some way that I can rewrite the URL of requests in the old format to be in the new format? It doesn't look like the S3 redirect rules are flexible to allow this, but can it be done in CloudFront instead?

MorayM
已提問 3 個月前檢視次數 244 次
3 個答案
0

If you're using CloudFront and want to transform the request, Lambda@Edge is a great option. [1]

[1] Lambda@Edge example functions - Working with query strings - examples - https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html#lambda-examples-query-string-examples

profile pictureAWS
已回答 3 個月前
0

Take a look at this workshop, shows how to do this with Lambda@Edge and CloudFront Functions.

Handling Rewrites and Redirects using Edge Functions

profile pictureAWS
專家
kentrad
已回答 3 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南