Redirecting your domain.com to www.domain.com does not requiere anymore to have a host/virtualhost and html redirection file, that was 10 years before!
Here is the practical way for AWS Route53 and Cloudflare:
1. AWS Route53:
Steps:
– Go to S3
– Create a new bucket named "domain.com"
– Properties –> Static WebSite Hosting
– Redirect all requests to another hostname
– www.domain.com should filled automatically
– Click "Save"
– Goto Route53
– Edit A record
– Select Alias Yes
– Select the s3 bucket you already created
– Click Yes
2. CloudFlare:
For Cloudflare it is much more easy, here it is:
– Open "Page Rules" tab
– Add new rule with "URL pattern "domain.com/*"
– Change Forwarding to On
– Enter Forwarding URL as "htttp://www.domain.com/$1"
– Choose 301 redirection
– Click "Add Rule"
The final should be as below: