Redirect subdomain URL to URL subdirectory on Amazon AWS

情到浓时终转凉″ 提交于 2019-12-09 05:24:44

问题


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 would redirect to mydomain.com/shop

DNS doesn't like resolving subdirectories like that... any suggestions?


回答1:


If I understand correctly, you want ALL requests to shop.mydomain.com to redirect to mydomain.com/shop.

In that case I recommend using S3's "Redirection Rules".

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.

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.

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

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!



来源:https://stackoverflow.com/questions/17728558/redirect-subdomain-url-to-url-subdirectory-on-amazon-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!