Question

Using CNAME for www redirection

  • Posted on April 27, 2015
  • DNS
  • EdGAsked by EdG

Currently, www.domain.net does not resolve to my http://domain.net.

Can I use a DNS CNAME record to fix this?

Would I simply put the ‘Enter Name’ field as ‘www.domain.net’ and the IP address used in the A record for the ‘Enter Hostname’ field?

Thanks,

Ed


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Can some one please explain how to do this as i need wwwmydomain,com to forward to mydomain.com

Assuming that you have the default created DNS record set up it will include a main record like this:

@  IN  A  [DROPLET_IP]

We can redirect a CNAME to this by doing the following:

www  CNAME   @

This will direct requests for www to the same IP as those for the domain without the www subdomain. You will still need to ensure that your web server is configured to handle the www subdomain properly. If you only run a single site on this droplet there shouldn’t be any more to do. If you are running multiple virtualhosts on the droplet you will need to either Add a ServerAlias directive (in Apache) or add the www.domain.com name to the server_name variable (in NGINX).

SOLVED (sortof). I noticed that any ServerAlias in my virtual host would end up with “index of /” and was not being redirected to the domain. I finally took out all aliases from the virtual host and everything works fine now. Obviously, I am missing a connection about why this is working and why it wasn’t before. Can anyone explain why?