Many have been searching for the configuration for redirecting www requests to non www or to root domain address and vice versa when having a hosted domain on Amazon AWS route 53. Unfortunately, Amazon AWS doesn’t support the traditional way of 301 redirections from www to non www using cname records. It returns a 404 error page. One approach for this issue is by adding alias name(A record) and creating an s3 bucket. To try this approach, your domain name records should be hosted with Route 53.
In this example, I will be implementing the configuration to redirect request from www to non www website. (for eg: www.example.com web requests will be redirected to http://example.com )
Initially, create a s3 bucket with name www.example.com
Once the bucket is created, go to the properties of the bucket. Under the static website hosting option, select the third option i.e Redirect all the requests to another host name. By default root domain address will be pre filled . Just select the radio button and hit save. Once you save, an end point will be created. Refer the snapshot for your reference.
Now go to Route 53 and lets edit the DNS files of the hosted domain. Click on Create a new record set.
Add the record name prefix as www. In our example record name looks like www.example.com Record type is “A-IPV4 address” Make is alias record by making the radio button to Yes. In Alias target field, once you place the mouse pointer. You can see a drop down listing the endpoints available. Select the end point under S3 Website endpoints, as show in below snapshot.
Now, hit on create button below to create the dns record. Now, go to browser and in the url field type the website name prefixed with www. You can see the redirection to non www website