如何使用CloudFront将所有URL子域重定向到其他URL子域?
我想重定向URL及其子域api.example.com/static/brands/*
www.example.com/brands/brands/*
。我的目标是,当客户端进入www.example.com/brands/*
所看到的网页是api.example.com/static/brand/brands/*
的网页。但是URL是www.example.com/brands/*
,因此对他来说是完全透明的。
域名api.example.com
正在重定向到ALB。
我对什么是逻辑有些困惑,如何用云方实现这一目标?
I want to redirect a url and their subdomains api.example.com/static/brands/*
to www.example.com/brands/*
. My goal is that when a client go in www.example.com/brands/*
the webpage seen is the webpage of api.example.com/static/brands/*
but the URL is www.example.com/brands/*
so it's totally transparent for him.
The domain name api.example.com
is redirecting to an ALB.
I am a bit confused about what is the logic, how can I achieve this with Cloudfront?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用CloudFront函数(在边缘执行的轻质JavaScript函数)。这是基于国家/地区进行重定向的示例参考 - 您可以根据自己的需求进行修改: https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/main/redirect-lase--con-con-on-country
You can use CloudFront Functions (lightweight JavaScript functions that execute at the edge). Here is an example reference of doing redirects based on country - you can modify based on your needs: https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/redirect-based-on-country
我相信您想要的是为
www.example.com
进行云额分散,该>具有Origin
api.example.com/static/brands/code>
和模式路径<代码>/brands/*将所有请求从
example.com/brands/*
重定向到原始api.example.com/static/brands/
I believe what you want is to make a cloudfront distrobution for
www.example.com
Which has an origin
api.example.com/static/brands/
and a pattern path
/brands/*
which redirects all requests fromexample.com/brands/*
to the originapi.example.com/static/brands/