How do I redirect WWW to naked domain with SSL in Amazon CloudFront?
June 5, 2024 2025-01-19 16:50How do I redirect WWW to naked domain with SSL in Amazon CloudFront?
How do I redirect WWW to naked domain with SSL in Amazon CloudFront?
To set up a CloudFront distribution that redirects from www.example.com to example.com (naked domain) with SSL, follow these steps:
I. Create SSL Certificates:
Obtain SSL certificates for both www.example.com and example.com using AWS Certificate Manager (ACM). Ensure the certificates are in the same region as your CloudFront distribution (usually us-east-1).
1. Go to the ACM console.
2. Request a certificate and include both www.example.com and example.com as domain names.
3. Validate the certificates via DNS or email.
II. Configure S3 Buckets:
1. Create two S3 buckets: one for example.com and one for www.example.com.
2. Set up the www.example.com bucket to redirect all requests to example.com:
* Go to the S3 console.
* Select the www.example.com bucket.
* Go to Properties -> Static website hosting.
* Choose “Redirect requests” and specify the target bucket name (example.com).
III. Set Up CloudFront Distributions:
Create a CloudFront distribution for example.com:
1. Go to the CloudFront console.
2. Click “Create Distribution”.
3. Choose “Web” and continue.
4. In the Origin Settings, set the origin domain to the S3 bucket for example.com.
5. Configure the Default Cache Behavior Settings and other necessary settings.
6. In the Distribution Settings, specify the alternate domain name (CNAME) as example.com.
7. Choose the SSL certificate for example.com from ACM.
Create a CloudFront distribution for www.example.com:
1. Go to the CloudFront console.
2. Click “Create Distribution”.
3. Choose “Web” and continue.
4. In the Origin Settings, set the origin domain to the S3 bucket for www.example.com.
5. Configure the Default Cache Behavior Settings and other necessary settings.
6. In the Distribution Settings, specify the alternate domain name (CNAME) as www.example.com.
7. Choose the SSL certificate for www.example.com from ACM.
IV. Configure DNS Settings:
1. In Route 53 or your DNS provider, create two records:
* An A record for example.com pointing to the CloudFront distribution for example.com.
* A CNAME or A record for www.example.com pointing to the CloudFront distribution for www.example.com.
V. Verify and Test:
* Wait for the CloudFront distributions to deploy.
* Test both www.example.com and example.com in a browser to ensure that www.example.com redirects to example.com and both use SSL.
By following these steps, you should be able to set up CloudFront to redirect from www to the naked domain with SSL successfully.