we are using amplify to host our nextjs app.
The domain provider is godaddy.
Amplify provided some steps to add 2 cname records and add forwarding according to this article:https://docs.aws.amazon.com/amplify/latest/userguide/to-add-a-custom-domain-managed-by-godaddy.html
we did all the steps but the issue now is: Our marketing team informs us that google is indexing www.example.com and example.com as 2 seperate sites and our audience is getting divided.
What i want to know is: How to redirect https://example.com to https://www.example.com with the hosting on aws amplify and godaddy as domain provider.
Followed official document by aws and still i am not able to solve the problem mentioned above
There are two solutions to this problem -
1. Create a Route53 Hosted Zone for your domain
You can create a hosted zone in Route53 for your domain and update the nameservers for your domain in Godaddy by pointing to the Route53 Hosted Zone nameservers. Please take a backup of the original nameservers and any existing records before updating the nameservers as you might need to replicate the records in Route53 or require the original nameservers if you wish to revert the changes.
Now you can create the CNAME records for ACM validation and www.example.com as stated in the amplify documentation and also create an ALIAS for example.com to point towards the CloudFront distribution.
2. Configure redirection through an application load balancer with static ip
This is a workaround and not a recommended option and might not fit your marketing usecase as well. If you want your DNS hosting to be on GoDaddy, and want https://example.com to redirect to https://www.example.com this will work for you. Please follow the steps below -
I. Create an application load balancer with HTTP and HTTPS listeners and add a redirection rule in both listeners to Redirect all requests to https://www.example.com. You will need to create an SSL certificate in ACM covering example.com and *.example.com to attach with the HTTPS listener.
II. In Application Load Balancer, go to Integrations and create a Global Accelerator which will provide static IP for the load balancer which you can directly map with example.com as an A record.
III. You can now map www.example.com with the CNAME records as shared in the article and https://example.com will perfectly redirect to https://www.example.com
Note:- If you just want to run the app on some subdomain you can create the Hosted Zone for that subdomain as well in Route53 and add NS records in Godaddy for the subdomain only.