0
votes

So I have a domain whose nameservers are pointed to AWS Route 53. My site is hosted on an EC2 instance and is reachable but only resolves to site.com, even if you input www.site.com. I'm curious how to get the site to resolve to www.site.com. I have under Route53 for my domains hosted zone 2 additional record sets outside of NS and SOA:

A site.com EC2 Elastic IP

CNAME www.site.com EC2 public DNS

I can reach the site using both site.com and www.site.com, but it will always resolve as site.com. Is there a way to make it so that if I enter either, it resolves to www.site.com?

1
This statement doesn't really make sense: "I can reach the site using both site.com and www.site.com, but it will always resolve as site.com". It sounds like the DNS for both names are resolving correctly if you can get to the site using either name. Perhaps you should describe exactly what is happening. It sounds like maybe the name in the browser is getting changed from www.site.com to site.com because your web server is probably configured to redirect all requests to site.com.Mark B
The DNS is working, but I'm asking how to change its resolution. if you type google.com it will redirect you to www.google.com. The question is asking how to configure Route53 to allow this.Lovetofly28
That's not a function of Route53, it's done via an HTTP redirect from a web server. It's not something a DNS server can do. All DNS does is resolve a domain name to an IP address. What you want isn't DNS resolution, it is HTTP request redirection.Mark B

1 Answers

0
votes

At first, both should be A record set.

A site.com EC2 Elastic IP
A www.site.com EC2 Elastic IP

And need redirect setting in your web server (nginx, apache, ..) as following. (Source: How To Redirect www to Non-www with Nginx on CentOS 7)

Redirect non-www to www

If you want redirect users from a plain, non-www domain to a www domain, add this server block:

server {
  server_name example.com;
  return 301 $scheme://www.example.com$request_uri; 
} 

Save and exit. This configures Nginx to redirect requests to "example.com" to "www.example.com". Note that there should be another server block that defines your www web server.