I have been reading other posts to try to get down to the bottom of this issue... but I need some clarification.
I am able to get all of my domain requests to hit my Amazon S3 bucket perfectly when entering www.example.com/MyDirectory
If I enter example.com/MyDirectory
without the www it will fail.
What is the proper method to make URL requests without the www route correctly to the same Amazon S3 bucket?
To enable static website hosting Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to enable static website hosting for.
You can use Amazon S3 to host a static website. On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts, such as PHP, JSP, or ASP.NET.
I finally came to the following solution:
I am using Namecheap for the DNS and Amazon S3 bucket with static hosting enabled...
The solution enables both the ability to access the root domain and the www domain. In the namecheap advanced DNS configuration I have the following settings:
CNAME Record @ domain.com.s3-website-us-west-1.amazonaws.com.
CNAME Record www www.domain.com.s3-website-us-west-1.amazonaws.com.
In the Amazon S3 configuration I have two separate buckets created.
[S3 Bucket #1]
Bucket name: www.example.com
Static website hosting set to:
"Enable website hosting"
[S3 Bucket #2]
Bucket name: example.com
Static website hosting set to:
"Redirect all requests to another host name" pointing to www.example.com (Bucket #1)
With this configuration any of my web traffic coming in on the root domain can hit the Amazon S3 bucket container example.com
and then auto redirect via Amazon to the primary S3 bucket www.example.com
that serves all of my static content.
If someone attempts to connect directly on the www domain it will go directly to the Amazon S3 container www.example.com
and not need to be redirected thru the example.com
bucket.
who is running into issues with making your root domain traffic route correctly.
So I used jremi's answer but as mentioned below had issues with email being delivered. After some time with NameCheap support, I have a working solution.
NameCheap setup
CNAME Record www example.com.s3-website-us-west-1.amazonaws.com.
URL Redirect Record @ www.example.com (unmasked)
S3 setup (only need 1 bucket)
[S3 Bucket]
Bucket name: www.example.com <---- This must match your domain exactly
Static website hosting set to:
"Enable website hosting"
S3 bucket Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.example.com/*"
}
]
}
This has allowed both example.com
and www.example.com
to work and my NameCheap email works as well.
I used sirclesam's method above and it got me 95% of the way there but my site still wouldn't load until I went and changed some configurations in my AWS S3 console.
Here are the steps to take:
www.example.com
)This worked for me. I had initially followed a guide which only indicated that one (the third) checkbox needed to be checked but that resulted in my bucket still blocking access so unchecking the last checkbox was what fixed the issue.
For further clarification, the first checkbox (which should be UNCHECKED) reads: "Block public access to buckets and objects granted through new public bucket policies" and the second checkbox (which should ALSO be UNCHECKED)reads: "Block public and cross-account access to buckets and objects through any public bucket policies"
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