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
asked 3 years ago809 views
1 Answer
0
Accepted Answer

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
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions