aws-samples / aws-samples/amazon-cloudfront-functions

Cut the .html from uri but remain querystring

Open
#7 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
533
Forks
76
PR merge metrics
No merged PRs in 30d

Description

I have no idea how to remain querystring on the full url?

Here my now code
```javascript
function handler(event) {
var request = event.request;
var uri = request.uri;

// Check whether the URI is end with .html
if (uri.includes(".html")) {
var newUri = uri.replace(".html", ""); // Delete .html from URI

var response = {
statusCode: 302,
statusDescription: "Found",
headers: { "location": { "value": newUri } }
};

return response; // Redirect user to new location without .html
}

return request; // Pass normal request to CloudFront
}
```

Let's say client request with

```
https://abc.xyz/index.html?region=ap-southeast-1
```
, So I want to redirect client to
```
https://abc.xyz/index?region=ap-southeast-1
```

but when I testing with real CloudFront Functions I got this result instead.
```
https://abc.xyz/index
```
This missing my query param. How to solve this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.