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.

Nir_Sh
已提問 3 年前檢視次數 818 次
1 個回答
0
已接受的答案

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
已回答 3 年前

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

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

回答問題指南