SPA on AWS S3 bucket using CloudFront with non WWW - amazon-web-services

I’m deploying a SPA in a S3 bucket. I’m using cloudfront to work through https. I need to redirect or delete the www in my domain (example.com). I tried this process:
create a s3 bucket to the www domain (www.example.com) and redirect all requests to the default domain (example.com)
create a distribution for www domain (www.example.com)
create an A type record in Route53 that points to the www distribution
The result is that it’s not redirecting to the non-www bucket. What is happening is that its waiting to find index.html (configured in the default root object) of the www bucket and is thus not redirecting to the other bucket (the non www one)
This is my S3 configuration:
And Cloudfront configuration:

Based on OP's feedback in the comment section, changing the CloudFront origin to use the website endpoint works.

Related

Website SEO From Non-WWW to WWW URL Using AWS S3 + CloudFront

I have a website on AWS S3 + CloudFront + Route 53.
The CloudFront dist Alternate domain names uses both www.example.com and example.com. also both records are managed with route53 posting to the Cloudfront dist.
I need to server both records, but SEO wise I need redirect the non-www to the www address.
When enabling redirect host in the bucket itself - I get too many redirect errors.
when removing the www. record - its not served on the net.
How can I bypass this using a single S3 bucket for both domains?
Thank you

AWS S3 website+cloudfront root domain redirect issues

I have my-domain.com. I want requests to the www subdomain to redirect to the root, and all requests to redirect to https.
I have 2 S3 buckets - my-domain.com and www.my-domain.com (empty bucket configured to redirect to my-domain.com)
I've set up a Cloudfront distro in front of my-domain.com for https.
For DNS, I have an A record for my-domain.com which is an 'alias' record pointing to the cloudfront distro. I have another A record for www.my-domain.com which is an 'alias' record pointing to the empty www.my-domain.com S3 redirection bucket
This results in the following redirects:
http://my-domain.com -> https://my-domain.com
http://www.my-domain.com -> https://my-domain.com
However a request to https://www.my-domain.com does not redirect. I'm presuming this is because there is no https listener for the S3 redirection bucket. So my question is, is there a better way to do this? I really don't want to have to set up another cloudfront distro just to have this functionality but it feels to me broken if https://www does not redirect correctly.
Thanks in advance,
#rix,
Perhaps this might be what you are looking for. [AWS S3 website+cloudfront root domain redirect issues]
(Cloudfront redirect www to naked domain with ssl)

Redirect naked domain to WWW in Route 53

I have seen a few questions about this but the answer is not working for me. I want to redirect the naked domain to www. I have my site deployed in a S3 bucket and a Cloudfront distribution.
This questions are similar:
https://serverfault.com/questions/576461/redirect-non-www-requests-to-www-on-amazon-route-53
How do I redirect a naked (apex) domain to www using Route 53?
This is what I have:
A static website in a S3 bucket: www.mysitename.com
Another website (empty) in a S3 bucket: mysitename.com configured to be redirecting everything to www.mysitename.com
A cloudfront distribution over the bucket www.mysitename.com
Route 53
Everything works well in the www.mysitename.com domain, but the naked domain is not working.
The ways it's configured in Route 53 is the following:
A Record, www.mysitename.com with Alias to my Cloudfront distribution (works perfect).
A Record, mysitename.com with Alias to my S3 bucket.
If I go to my "mysitename.com.s3-...." S3 bucket it redirects correctly to the other bucket. But If I go to the naked domain, it doesn't work.
The error I get is:
This site can’t be reached xxxxxxxx.com took too long to respond.
Try: Checking the connection Checking the proxy and the firewall Running Network Diagnostics ERR_CONNECTION_TIMED_OUT
It resolves to a Amazon S3 IP correctly. If I go to the IP it opens https://aws.amazon.com/s3/.
What am I missing?
https://forums.aws.amazon.com/thread.jspa?threadID=55995
Shortcut:
Just point your naked/root domain to 174.129.25.170 and all requests to example.com will be redirected to www.example.com
No signup needed, uptime is published on a website.
It is an EC2 instance doing only redirects.
Full disclosure: User "Dima" made this service.

AWS S3 CloudFront - redirect from https://www.domain.com to https://domain.com

Here is my AWS Route 53 Setup:
The domain https://www.migranthire.com doesn't work. How can i redirect from this domain to https://migranthire.com
Your www site is pointing directly to an S3 bucket web site hosting endpoint, which is taking care of the redirect to the domain name without the www prefix.
The S3 website endpoints do not support HTTPS, so this works for http only.
Your solution is to create a second CloudFront distribution -- you need an additional one, because the second one has a different origin. Configure this distribution with your SSL certificate, configured to expect the www hostname as an alternative name, and set its origin to the www bucket -- however, when you are setting up this second CloudFront distribution, do not select the name of your bucket from the list. Instead, enter the website endpoint hostname -- www.migranthire.com.s3-website-eu-west-1.amazonaws.com. Set the origin protocol to HTTP only (CloudFront has to send the request to the bucket as HTTP even if the viewer protocol is HTTPS. You still get a green lock.)
Then, configure Route 53 to send www requests to the new CloudFront distribution, instead of directly to the bucket. CloudFront will speak SSL, sent the request to S3, which will return the redirect, as it is doing now.

How to redirect non www to www in aws s3 bucket and cloudfront

I know how to redirect/rewrite non-www to www using .htaccess in apache server. But I have no clue, about s3 bucket, and CloudFront. I have hosted the website on an s3 bucket using CloudFront.
How do I redirect all http://example.com/ requests to http://www.example.com
Create a www.example.com S3 bucket and place all the code in this bucket
Create a example.com S3 bucket and set redirect to www.example.com as mentioned in https://aws.amazon.com/blogs/aws/root-domain-website-hosting-for-amazon-s3/
Create CloudFront and configure with S3 bucket link of www.example.com and add cname entry only for www.example.com.
In Route 53 for www.example.com point alias as CloudFront link related to S3 bucket
In Route 53 for example.com point alias S3 bucket of example.com
There is a feature in S3 where you can to this. Select a bucket, in Properties under Static Web Hosting select Redirect all requests to another host name.
Read more here: https://aws.amazon.com/blogs/aws/root-domain-website-hosting-for-amazon-s3/
Update from comment:
Add a cname in your domain setup for example.com to point to your bucket endpoint and a cname for your www.example.com to point to the cloudfront endpoint.