【问题标题】:how can I set Alias Redirection in AWS S3 website CloudFront?如何在 AWS S3 网站 CloudFront 中设置别名重定向?
【发布时间】:2021-12-16 01:08:03
【问题描述】:

我有一个在 apex 域 (xxx.com) 工作的主要网站,现在有一个短期项目,它只是一个登录页面,使用 Gatsby4(React) 作为 S3 存储桶中的所有静态文件部署,并设置适当的 Cloudfront https工作的分发

现在有https://landingpage.xxx.com 可以工作了,但是又长又难记,还想设置一个短别名,

当用户在地址栏中输入lp.xxx.com时,它应该做HTTP 301重定向到目的地https://landingpage.xxx.com;我已在 Route53 中将此 lp.xxx.com 设置为 CNAME landingpage.xxx.com 并将 lp.xxx.com 添加到 Cloudfront Altname,

所以现在https://lp.xxx.com 正在工作(以及https://landingpage.xxx.com),但它就像两个不同的入口一样工作,没有重定向,

想知道我在某处错过了一个简单的重定向规则设置吗?避免更改 Gatsby4(React) 代码;这需要一些 Lambda@Edge 函数吗?

【问题讨论】:

    标签: amazon-web-services amazon-cloudfront amazon-route53


    【解决方案1】:

    我正在使用 CloudFront 函数重定向解决它:

    修改自此示例代码https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example-function-redirect-url.html

    function handler(event) {
        var request = event.request;
        var headers = request.headers;
        var host = request.headers.host.value;
    
        if (host !== 'landingpage.xxx.com') {
            var response = {
                statusCode: 302,
                statusDescription: 'Found',
                headers:
                    { "location": { "value": 'https://landingpage.xxx.com' } }
                }
            return response;
        }
        return request;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 1970-01-01
      • 2019-04-24
      • 2017-05-14
      • 2018-09-05
      • 2020-10-24
      • 2020-11-18
      • 1970-01-01
      • 2016-12-08
      相关资源
      最近更新 更多