【问题标题】:I need to redirection for my url using cloudfront and s3我需要使用 cloudfront 和 s3 重定向我的 url
【发布时间】:2020-11-06 03:15:25
【问题描述】:

我有一个网址说example.com/eu/blog/,在这个页面上,我有一个按钮,当任何用户点击按钮时,它会转到oil-gas.com/en(这是一个不同的网站)..现在我想要这个链接作为example.com/eu/blog/oil-gas/en,目前我在example.com/eu/blog/oil-gas/en 中没有任何内容。

我使用了 apache proxypass 并且它可以工作,但我想知道我们是否可以使用 S3、cloudfront 来做到这一点.. 我们可以在 S3 中创建存储桶并启用带有重定向的静态托管...我希望 url 具体example.com/eu/blog/oil-gas/en。请提供更多帮助或建议

【问题讨论】:

    标签: amazon-web-services url redirect amazon-s3 amazon-cloudfront


    【解决方案1】:

    您可以通过添加 Lambda@Edge 函数在 CloudFront 中设置重定向。这将被添加到 Origin Response 事件中。

    代码如下所示

     def lambda_handler(event, context):
     
         request = event["Records"][0]["cf"]["request"]
         response = event["Records"][0]["cf"]["response"]
         
         #If it matches this path perform a redirect
         if request['uri'] == "url/to/redirect":
        
             response = {
                 'status': '302',
                 'statusDescription': 'Found',
                 'headers': {
                     'location': [{
                         'key': 'Location',
                         'value': 'http://example.com/eu/blog/oil-gas/en'
                     }]
                 }
             }
         
         return response
    

    这里有一些examples

    【讨论】:

      猜你喜欢
      • 2014-05-09
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2015-02-27
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多