views:

1839

answers:

4

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

A: 

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
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
No editable template? Not even a teeny-weeny part of the header where you can add, for example, statistics related code? Brrrr....
David Hanak
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
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
+1  A: 

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
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
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
+3  A: 

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
What I did was this:1. Setup an A record on the DNS @ A target.it.address2. Setup an A record to forward the www. to a hobby site where I could host a PHP redirect:www A hobby.ip.address3. Create a PHP file with 301 and redirect headerGreat help from everybody; this answer helped me the most
iopener
A: 

I have a different but similar question. I have a dynamic dns account where I map my machine's dynamic IP to an address say, www.xxx.yyy.net

Now, I have registered another short domain name say www.yyy.com, the hosting is on a linux server.

Now, my machine is actually a webserver which runs .net website which can be accessed by www.xxx.yyy.net I need my homepage(index.php) in my www.yyy.com handle the redirection in a way that the pages to be loaded from www.xxx.yyy.net/.... but it should look in the browser as www.yyy.com/...

Is there any way to do this?

Berny Paul
post this as a different question
modosansreves