I host my site at domain.com
.
My DNS entries in Route53 are as follows:
domain.com A xxx.xxx.xxx.xxx 300
domain.com NS stuff.awsdns-47.org 172800
domain.com SOA stuff.awsdns-47.org 900
I would like to redirect traffic from www.domain.com
to domain.com
, as currently this just returns a 404. This question on SO suggested a PTR
record, and I added that:
www.domain.com PTR domain.com 300
but it didn't work. What should I be doing?
PTR is for setting up reverse IP lookups, and it's not something you should care about. Remove it.
What you need is a CNAME for www:
You can also set a ALIAS for WWW to A record of domain.com:
so your final DNS entries would be as follows:
I was able to get this set up by leveraging an additional S3 bucket.
I want my website to be accessible at the non-www
example.com
. In my case,example.com
is set up with a route 53 hosted zone, a s3 bucket, and a cloudfront distribution with a custom ssl cert.I want
www.example.com
to redirect toexample.com
. To do so, I set up a new s3 bucket forwww.example.com
. I set it to public and set up static website hosting to redirect all requests. The target bucket or domain isexample.com
. Since I have the ssl cert configured onexample.com
, I set the protocol to https.In route 53, within the mydomain.com hosted zone, I created a new A record for
www.example.com
with an Alias that pointed to the new www s3 bucket website.Now all requests to
www.example.com
redirect tohttps://example.com
.Hope this helps.
After you have a CNAME for both example.com and www.example.com this nginx config will redirect traffic from http to https as well as all www.example.com to example.com
where my actual server is up and listening on port 3000 ... this also terminates my TLS however just remove mention of ssl ... tucked away in those included files are my nginx settings to harden the box
As mentioned above, it's not possible with standard DNS.
Here's the solution I used:
After meddle up with lots of online tutorials, I found it was very easy without the need for any service other than Route53.
This is the example configuration for the domain with www,
This is an example configuration for the same domain without www,
So basically you have to copy the same configuration including the IP address again from www.domain.com to domain.com.
And that's it wait for some time to get your domain changes to propagate and you'll be able to see your website loading both in the domain with and without www.
It depends on how you are serving the site. The easest way is probably serve through cloudfront. That way you would simpley create the cloudfront distribution and add both the www and non-www domain as alias'. Cloudfront will take care of both.