Last active
May 18, 2019 19:18
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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, | |
}] | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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