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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则