Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters
Last active May 18, 2019 19:18
Show Gist options
  • Save chrisdpeters/88fbe16b56bfe7cfee8fa066f11298d7 to your computer and use it in GitHub Desktop.
Save chrisdpeters/88fbe16b56bfe7cfee8fa066f11298d7 to your computer and use it in GitHub Desktop.
Setting up all kinds of domain redirects in S3 and CloudFront http://blog.chrisdpeters.com/domain-redirects-s3-and-cloudfront/
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
let uri = request.uri ? request.uri : '/';
if (request.querystring) {
uri += '?' + request.querystring;
}
const redirectTo = 'https://www.example.com/de' + uri;
callback(null, {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
key: 'Location',
value: redirectTo,
}]
}
});
};
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals/>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>www.example.org</HostName>
<ReplaceKeyWith></ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment