diff --git a/docs/cloudformation/geo-ca-stack.yml b/docs/cloudformation/geo-ca-stack.yml index 231c4e7..3d6a9d9 100644 --- a/docs/cloudformation/geo-ca-stack.yml +++ b/docs/cloudformation/geo-ca-stack.yml @@ -326,21 +326,26 @@ Resources: else if (!uri.includes('.')) { request.uri += '/index.html'; } - // Redirects requests to the www. url to the non www. url. if (request.headers && request.headers.host && request.headers.host.value.includes('www.')) { - var newurl = request.headers.host.value.replace('www.', '') - var response = { - statusCode: 301, - statusDescription: 'Moved Permanently', - headers: - { "location": { "value": 'https://' + newurl + request.uri } } - } - return response; + var newurl = request.headers.host.value.replace('www.', '') + var qs = '' + Object.keys(request.querystring).forEach((e) => { + if (qs === '') { + qs += '?'; + } else { qs += '&' }; + qs += e + '=' + request.querystring[e].value; + }) + var response = { + statusCode: 301, + statusDescription: 'Moved Permanently', + headers: + { "location": { "value": 'https://' + newurl + request.uri + qs } } + } + return response; } - return request; - } + } FunctionConfig: Comment: A function run on every request to geo.ca Runtime: cloudfront-js-1.0