Reputation: 2256
First of all my stack is a very simple one on AWS. I have these three services:
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?
Upvotes: 3
Views: 1691
Reputation: 494
Here is one possible solution:
You CloudFront configuration needs to define another distribution what will be the root file/folder.
The CloudFront distribution should point to mydomain.com/shop
. Create another distribution and make sure to point to the S3 Bucket public URL and don't forget to put the path to the subfolder there. Do not forget to put the right CNAME when creating the distribution, the CNAME must be the subdomain you're using, e.g. shop.mydomain.com
without this it won't work.
Now, you need to create a new entry on Route 53 and point it to the new CloudFront distribution. So, create an entry with your subdomain and select CloudFront link to link with your new distribution. If everything ran correctly your distribution will appear there.
That's it.
Upvotes: 3