Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect subdomain URL to URL subdirectory on Amazon AWS

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?

like image 709
sea26.2 Avatar asked Jul 18 '13 16:07

sea26.2


People also ask

Does AWS offer URL forwarding?

The steps outlined here can be used to set up URL forwarding to any URL, not just ones from Amazon. You will learn how to set up forwarding to specific folders (like /console in my example), and how to change the protocol of the redirect from HTTP to HTTPS (or vice versa).


1 Answers

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.

AWS Console Edit Redirection Rules Screenshot

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!

like image 132
secretmike Avatar answered Sep 28 '22 02:09

secretmike