First of all my stack is a very simple one on AWS. I have these three services:
- S3 Bucket hosting my website
- CloudFront pointing to my S3 Bucket
- Route 53 pointing to CloudFront
So, what I'm trying to do is to redirect a subdomain to a subfolder inside my S3 bucket. Something like this: shop.mydomain.com
-> mydomain.com/shop
.
I tried S3 Bucket redirect rules, mentioned in this answer Redirect subdomain URL to URL subdirectory on Amazon AWS but what I got was shop.mydomain.com
-> mydomain.com/shop/shop/shop/...
EDIT:
My S3 Bucket is in "Host Website" mode, and this is the redirect config I tried to use:
<RoutingRules>
<RoutingRule>
<Redirect>
<Protocol>https</Protocol>
<HostName>mydomain.com</HostName>
<ReplaceKeyPrefixWith>shop/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
My CloudFront is pointing correctly to the bucket, and also the route 53 is pointing correctly to CloudFront. In that case mydomain.com
is working fine.
Can someone please help me on that?