11

I am running a blog at posterous.com, and they can host my domain name if I create an A record to their IP in my domain registrar's custom DNS tool.

The problem is that I want my domain to ALWAYS read domain.com, so I want to have my DNS remap any requests to www.domain.com to domain.com, and I can't use .htaccess or PHP or other server methods, since it's just a blog interface.

So far, I've tried:

@ A target.ip.address
www CNAME domain.com

Which redirects www.domain.com to the right site, but the www. is still on the domain. I heard you could do:

@ A target.ip.address
www A internal.redirector.ip.address

but I don't know my registrar's internal IP address that might handle this redirection (or even if such a thing actually exists).

Can what I'm asking for be done?

Thanks, you guys rock.

-Josh

iopener
  • 547
  • 1
  • 9
  • 24

3 Answers3

17

No, you can't do this with DNS - the result of the DNS query doesn't change what happens in the HTTP layer so the originally entered domain name will always be the one that's sent to the web server in the Host: header.

Web browsers only look up A records in the DNS, and it's the user's ISP's recursive name server which detects that the name actually only has a CNAME record, which it then looks up, and returns the IP address corresponding to that name in the CNAME record.

The usual C gethostbyname() API doesn't return any of that CNAME information to the application, all it ever gets is the final resulting IP address.

To achieve what you want you'd need to arrange for www.example.com to have separate hosting from your blog, and then have that site do an HTTP redirect to example.com (i.e. without the www prefix)

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • What I did was this: 1. Setup an A record on the DNS @ A target.it.address 2. Setup an A record to forward the www. to a hobby site where I could host a PHP redirect: www A hobby.ip.address 3. Create a PHP file with 301 and redirect header Great help from everybody; this answer helped me the most – iopener Feb 27 '09 at 19:05
3

Can what I'm asking for be done?

No, not with DNS.

You could setup something with something like a dyndns.com webhop. Basically you point www.posterous.com at the dyndns server, when a browser connects they send an HTTP 302 redirect to the url you want (posterous.com).

http://www.dyndns.com/services/webredirect/

Zoredache
  • 37,543
  • 7
  • 45
  • 61
  • There must be some good technical/security reason why the DNS won't get involved in rewriting the URL, I suppose. Thanks for your input. I'm going to leave the question open for a bit and see if i get any other suggestions before I check your answer and admit defeat :) – iopener Feb 27 '09 at 09:27
  • it's called a "layering violation". Whatever the user typed *has* to be what goes into the Host: header - the DNS is only there to figure out which IP address those headers get sent to. – Alnitak Feb 27 '09 at 09:43
1

I'm not sure if you can do this with DNS, but I'm positive that you can perform it with some javascript trickery in your blog template. I.e., a javascript snippet that is run on each page load could check the server of the current page, and rewrite the location if this matches the "www." prefix. Granted, there will be some flickering as the page loads and then reloads, and search engines will also disregard this redirect, so your content might show up under the wrong address in search results, but at least the users will see the correct, intended address.

Alternative idea: If your DNS registrar provides free-of-charge web service in addition, do the redirection there, add a rewrite rule to translate the request path to a script argument, and for each request, generate a simple page with an iframe accessing the real content. This again requires some PHP coding, but it shouldn't be too difficult.

David Hanak
  • 10,754
  • 3
  • 31
  • 39
  • Good idea, but posterous.com is a pretty simplistic engine (beautifully so, but this problem I'm having is one minor pain), and there is no "template" you can update. I'd have to embed the javascript in every post, and then make sure it didn't re-run on pages that listed all the posts... gong show. – iopener Feb 27 '09 at 07:40
  • No editable template? Not even a teeny-weeny part of the header where you can add, for example, statistics related code? Brrrr.... – David Hanak Feb 27 '09 at 08:01
  • I know. It's very hands-off, but it will keep me from constantly fiddling instead of actually WRITING :) They incorporate tons of automated stuff, like auto-cross posting to twitter, flickr, etc., and even integrating Google Analytics. This is a tiny, anal problem compared to all the benefits – iopener Feb 27 '09 at 08:20
  • Thanks for the alernative idea; there are lots of scripted ways I could solve this, but I was hoping for a nice clean DNS-only solution. – iopener Feb 27 '09 at 09:23