【问题标题】:How to redirect with Heroku / Amazon cloudfront / route 53如何使用 Heroku / Amazon cloudfront / route 53 重定向
【发布时间】:2018-04-01 10:41:33
【问题描述】:

我在 heroku 上托管单页应用程序并使用 amazon cloudfront,路由 53。现在我想在不接触源代码的情况下将一些内部路由重定向到其他路由。

例如

http://example.com/foo -> http://example.com/bar

是否可以使用一些云端或路由 53 配置?

【问题讨论】:

    标签: heroku amazon-cloudfront amazon-route53


    【解决方案1】:

    您可以通过多种方式做到这一点。

    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);
    };
    

    参考: http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html

    API-网关:

    创建一个 http 代理并执行重定向到所需的 url。 您还需要创建源并将来自云端的行为关联到此 api-gateway 端点。

    带有 Lambda 的 API 网关:

    通过 ANY 集成将 url 传递给 API-Gateway,然后到达 Lambda,您可以返回相同的响应。

    'use strict';
    
    exports.handler = function(event, context, callback) {
        var response = {
            statusCode: 301,
            headers: {
                "Location" : "https://example.com"
            },
            body: null
        };
        callback(null, response);
    };
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 2013-02-17
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2013-12-31
      • 2017-06-02
      • 2012-07-07
      相关资源
      最近更新 更多