11

Here is the problem: we host our website with an external provider that doesn't give us an IP address, rather, they give us a domain where we point our www CNAME record to. I assume they are using some type of virtual hosting that reads the header for the requested domain and displays that website.

Anyway, a lot of our users complain the website is down when it actually is not because they are typing example.com instead of www.example.com into their browsers.

Is there a way to make this work in our DNS?

Alex
  • 6,477
  • 1
  • 23
  • 32
Ryan Mortier
  • 488
  • 3
  • 8
  • 19

4 Answers4

11

CNAME'ing your root is generally a bad idea, as all of the other records on the root (SOA, NS, MX) tend to be pretty important.

Your provider should really be allowing you to point to an address instead of a name. I appreciate what they're trying to do, giving themselves more flexibility to mess with that DNS entry as needed, but in this case it's counterproductive.

Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • You're right, we can't CNAME our root because of the other records. Unfortunately, the provider will not provide an IP address for our site (even though we pay good money for them to host it). Is there any other way to have http traffic going to example.com to be redirected to www.example.com on our end? – Ryan Mortier May 26 '11 at 15:39
  • 2
    Well, yes, but it's not a good solution. You could put up an HTTP server somewhere that you point to via an A record on the root, which will then send a 301 redirect on all incoming requests to send them to www.example.com. But, that makes no sense from a financial perspective, when you're already paying good money for hosting. Try explaining the situation to your provider, they may see the error of their ways.. – Shane Madden May 26 '11 at 15:43
11

OK, this was asked some time ago, and there is already an accepted answer...

CNAME'ing your root is generally a bad idea,

You must not use a CNAME for your root example.com domain.

users complain the website is down [..] because they are typing example.com instead of www.example.com

There is a simple solution:

  • Point example.com at the IP address (A Record) of a webserver,
  • which sends out an HTTP 301 redirect to your www.example.com address.

This redirect takes at most perhaps two hundred milliseconds, and most users never notice it.

You can do this yourself, by setting up a webserver and a few lines of PHP / ASP / .HTACCCES etc. Note, this doesn't have to be your main production webserver; any cheap shared webhost with a static IP address will do.

Alternatively, many DNS hosting providers have this as a free-of-charge service. This would be the simplest & most robust option; leave it to someone specialized in this to host this redirect. Different DNS hosts tend to call this functionality by different names, for example Gandi calls it "Web Forwarding".

Is there a way to make this work in our DNS?

You mean, purely in DNS without using a webserver? No, there is not.

1

Assuming the IP the CNAME resolves to doesn't change often and there isn't anything too fancy happening (e.g. geo-based load balancing, use of CDNs, etc.) you could "cheat" and add an A RR for example.com with the IP the CNAME resolves to. I'd set up automated monitoring and changing of the A records so that if the IP does change it will be handled automatically (and you'd probably want a low TTL on the RR as well).

Unfortunately Alex's consideration would still apply: you'd need to configure the web server to do the right thing when the Host: header is example.com rather than www.example.com.

Regarding Shane Madden's comment about setting up another web server to do the redirects: some DNS providers have this service. For example, DynDNS has "WebHops." http://www.dyndns.com/support/kb/webhops_redirections.html You'd create an A record for example.com with IP 204.13.248.125 and then create a "webhop" that will redirect to www.example.com.

In the end, it may be time to get a new web hosting service that has the features you need.

Mark Wagner
  • 17,764
  • 2
  • 30
  • 47
0

After my question, the more I thought about it, it sounds like you do own the DNS for the zone. The problem is going to be, if they have a virtualhost setup for www.example.com, it will not answer for example.com. In order to make that work, you'd have to have something else answering for example.com, and have the webserver do a redirect to www.example.com.

Alex
  • 6,477
  • 1
  • 23
  • 32
  • We do have full control of the zone file for our domain name, unfortunately we do not have any access to the web server itself. Bummer :( – Ryan Mortier May 26 '11 at 15:37