将子域 URL 重定向到 Amazon AWS 上的 URL 子目录 [英] Redirect subdomain URL to URL subdirectory on Amazon AWS
问题描述
我们通过 AWS 上的 Route 53 创建了一个指向外部服务器的子域.我们现在想将该流量重定向回主域,但重定向到子目录.
We've created a subdomain via Route 53 on AWS that points to an external server. We now want to redirect that traffic back to the main domain, but to a subdirectory.
shop.mydomain.com 将重定向到 mydomain.com/shop
shop.mydomain.com would redirect to mydomain.com/shop
DNS 不喜欢那样解析子目录...有什么建议吗?
DNS doesn't like resolving subdirectories like that... any suggestions?
推荐答案
如果我理解正确,您希望对 shop.mydomain.com
的所有请求重定向到 mydomain.com/shop
.
If I understand correctly, you want ALL requests to shop.mydomain.com
to redirect to mydomain.com/shop
.
在这种情况下,我建议使用 S3 的重定向规则".
In that case I recommend using S3's "Redirection Rules".
在 S3 中创建一个名为 shop.mydomain.com
的存储桶.打开存储桶属性并将存储桶设置为启用网站托管".然后选择编辑重定向规则"选项.
Create a bucket in S3 called shop.mydomain.com
. Open the bucket properties and set the bucket to "Enable Website Hosting". Then select the "Edit Redirection Rules" option.
我们现在需要定义一个匹配每个请求的重定向规则,并将其重定向到mydomain.com/shop
We now need to define a redirection rule that matches every request, and redirects it to mydomain.com/shop
<RoutingRules>
<RoutingRule>
<Redirect>
<Protocol>https</Protocol>
<HostName>mydomain.com</HostName>
<ReplaceKeyPrefixWith>shop/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
此规则将匹配每个请求并将其重定向.
This rule will match every request and redirect it.
有关路由规则的更多信息,请查看官方文档:http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html#configure-bucket-as-website-routing-rule-syntax
For more info on routing rules, check out the official docs: http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html#configure-bucket-as-website-routing-rule-syntax
现在,您需要在 Amazon Route 53 中将 shop.mydomain.com
配置为指向您刚刚创建的存储桶 shop.mydomain 的
.ALIAS
记录.com
Now, you need to configure shop.mydomain.com
in Amazon Route 53 as an ALIAS
record pointing at the bucket you just created, shop.mydomain.com
.
就是这样 - 享受吧!
That's it - Enjoy!
这篇关于将子域 URL 重定向到 Amazon AWS 上的 URL 子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!