I’m looking to implement URI Rewrite Logic with Javascript with CloudFront functions.
Looking at many articles and it shows for all for URI Redirect. How can I implement this code (I’m all new to Javascript).
This is required to see how cloudfront making request to the origin (not looking for Lambda@Edge currently).
Trying with the logic, but not I’m able to make it work.
function handler(event) {
var request = event.request;
var uri = request.uri;
// Example rewrite rule: rewrite "/old-path" to "/new-path"
if (uri.startsWith('/old-path')) {
request.uri = uri.replace('/old-path', '/new-path');
}
// Return the modified request to CloudFront
return request;
}