Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters chrisdpeters/index.js

Last active May 18, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.