如何使用Heroku/Amazon cloudfront/route 53重定向
我在heroku上托管单页应用程序,并使用amazon cloudfront,route 53。现在我想将一些内部路由重定向到另一个路由,而不涉及源代码 比如说如何使用Heroku/Amazon cloudfront/route 53重定向,heroku,amazon-cloudfront,amazon-route53,Heroku,Amazon Cloudfront,Amazon Route53,我在heroku上托管单页应用程序,并使用amazon cloudfront,route 53。现在我想将一些内部路由重定向到另一个路由,而不涉及源代码 比如说 http://example.com/foo -> http://example.com/bar 使用cloudfront或route 53配置是否可行?您可以通过多种方式实现 Lambda@Edge: 您可以为查看器请求创建lambda边缘函数并执行重定向 'use strict'; exports.handler = (ev
http://example.com/foo -> http://example.com/bar
使用cloudfront或route 53配置是否可行?您可以通过多种方式实现 Lambda@Edge: 您可以为查看器请求创建lambda边缘函数并执行重定向
'use strict';
exports.handler = (event, context, callback) => {
/*
* Generate HTTP redirect response with 302 status code and Location header.
*/
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html',
}],
},
};
callback(null, response);
};
参考:
API网关:
创建http代理并执行重定向到所需url。
您还需要创建源并将cloudfront的行为与此api网关端点相关联
带Lambda的API网关:
通过任何集成将url传递到API网关,并将其传递到Lambda,您可以返回相同的响应
'use strict';
exports.handler = function(event, context, callback) {
var response = {
statusCode: 301,
headers: {
"Location" : "https://example.com"
},
body: null
};
callback(null, response);
};
希望能有帮助