Lambda@Edge Redirect when URL ends with #

0

My customer hosts a static website on S3, fronted by CloudFront. They rolled out a version that leads to an invalid URL: www.example.com/test1/#

They would like to redirect all test1/# requests to test1/index.html

I thought of two options that failed:

A. Lambda@Edge redirect: Failed, because the parameter "#" is invalid when defining a behavior:

com.amazonaws.services.cloudfront.model.InvalidArgumentException: The parameter globPattern can only contain these characters: [a-zA-Z0-9_-.*$/~"'&@:?+\]. (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidArgument; Request ID: d0; Proxy: null)

B. Uploading a file called "#" and edit its metadata to redirect but it doesn't work. CloudFront allows me to download the file.

1 Antwort
0
Akzeptierte Antwort

The problem is that the "#" is a directive to the browser, and does not get sent to the server, whether it is Lambda@Edge or any other server. For example if I request:

https://example.com/test/#

Then this gets sent to the Lambda:

"method": "GET",
"querystring": "",
"uri": "/test/"

If there were text after the #, then you could access it in client-side JS via location.hash

profile pictureAWS
beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen