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?

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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠