Home > database >  Redirect directories to individual s3 buckets?
Redirect directories to individual s3 buckets?

Time:10-04

I have a Laravel application hosted on a domain. I have several dynamic directories ie:

example.com/directory

example.com/random

example.com/moon

I would like each of these directories to resolve to a different s3 bucket while masking the URL (I want to see the URL above, not the s3 bucket URL). What's the best way to accomplish this? I could possibly create a primary bucket and host example.com on it and create routing rules on that s3 bucket to redirect to the other s3 buckets (I think). What do those routing rules look like? I was unable to find directions in the AWS documentation that showed how to redirect to other buckets. Is there another, more simple way to go about this?

It's worth noting the Laravel application may not need to be involved in the actual routing as much as using the AWS sdk to dynamically configure the directories.

CodePudding user response:

You have to use Route53 along with S3 enabling static website hosting.

For detail configuration about static website hosting in S3, you can take a look here.

After that choose Route53 as a service in AWS Console.

Select your hosted zone and add a CNAME recordset, in the value field enter the S3 bucket endpoint url and in the Name field enter the url that you want to point to the S3 bucket.

For using Route53 you can read this AWS document.

CodePudding user response:

The best way would be to create a CloudFront (CF) distribution with three different origins. Then each origin would respond to different Origin Path which would lead to different buckets.

example.com could be defined in Route53, with Alias A record to the CF distribution. The benefit of using CF with S3 is that you not only can speed up your website (CF is CDN), but also you can keep your buckets and objects private:

  • Related