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?
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).
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With