I see people talking about how to rewrite a URI based on various information. But I'd like to normalize the domain name that is being requested. Here's what I've tried:
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
if (request.method.toUpperCase() != 'GET') {
callback(null, request);
return;
}
request.origin = {
custom: {
domainName: 'slashdot.org',
port: 443,
protocol: 'https',
path: request.uri
}
};
request.headers.host = {
"key": "Host",
"value": request.origin.custom.domainName
};
console.log("returning req:", request);
callback(null, request);
}
I was hoping that would pull up the request and that cloudfront would then make a request against my canonicalized domain. (for the example and testing, I'm using slashdot, since it's obvious it isn't my content).
Ultimately, I'm trying to canonicalize a request without doing redirects, but instead rewriting the request before hit hits the origin.