You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have no idea how to remain querystring on the full url?
Here my now code
functionhandler(event){varrequest=event.request;varuri=request.uri;// Check whether the URI is end with .htmlif(uri.includes(".html")){varnewUri=uri.replace(".html","");// Delete .html from URIvarresponse={statusCode: 302,statusDescription: "Found",headers: {"location": {"value": newUri}}};returnresponse;// Redirect user to new location without .html}returnrequest;// 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?
The text was updated successfully, but these errors were encountered:
I manual mapping into new url, but have another great idea for deal with this issue?
functionobjectToQueryString(obj){varstr=[];for(varparaminobj)if(obj.hasOwnProperty(param)){str.push(encodeURIComponent(param)+"="+encodeURIComponent(obj[param]['value']));}returnstr.join("&");}functionhandler(event){varrequest=event.request;varuri=request.uri;// Check whether the URI is end with .htmlif(uri.endsWith(".html")){varnewURI=uri.substring(0,uri.length-5);// Delete .html from URIvarredirectUrl=`https://${request.headers.host.value}${newURI}?${objectToQueryString(request.querystring)}`;varresponse={statusCode: 302,statusDescription: "Found",headers: {"location": {"value": redirectUrl}}};returnresponse;// Redirect user to new location without .html}returnrequest;// Pass normal request to CloudFront}
I have no idea how to remain querystring on the full url?
Here my now code
Let's say client request with
, So I want to redirect client to
but when I testing with real CloudFront Functions I got this result instead.
This missing my query param. How to solve this?
The text was updated successfully, but these errors were encountered: