Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a DNS server running at "" I have full control of the Apache server (same server as and the dns records themselves. I wanted to supply a service where people would type into their A record, and when someone accessed the site, would redirect to (set to their actual IP). Essentially the same thing as Would I configure this in Apache or my DNS?

share|improve this question
+1 for the idea, I thought about this myself a few weeks ago but never got round to it. – Smudge Jul 28 '11 at 13:51
@samarudge likewise - the real problem is getting yourself an IP that you can guarantee won't ever be revoked, since every single client of the service must (by definition) use the naked IP, and not a DNS name. – Alnitak Jul 28 '11 at 15:00
@Alnitak Hmm hadn't thought about that. also could be a lot of traffic and no way to promote/monetize the service. Still it's one of those "It would make it easier, but I can't be bothered" kind of things =) – Smudge Jul 28 '11 at 16:30
@samarudge yeah, tricky, especially when there's PCI compliance to sort out... ;-) – Alnitak Jul 28 '11 at 17:44
cough Just going to leave this here and hope someone finds it useful – Chris S Sep 8 '11 at 14:55
up vote 1 down vote accepted

This should be configured in Apache, set up a virtual host to listen on that IP (with no other VHosts listening) then use a rewrite rule to redirect.

Something along the lines of

ServerName redirector
DocumentRoot /var/www/html/
<Location />
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301] 

(Note: Code not tested, guessing from memory but it should be something along those lines)

share|improve this answer
Thanks. What if, perhaps, I set up the thing to listen for "" port 80, where the user sets their site to go to CNAME instead of the A-name to my IP? Would I then be able to host a site there as well? – U4iK_HaZe Jul 28 '11 at 14:06
I don't think you can use CNames on naked domains (Might be wrong). But you could host multiple sites on that IP so long as the redirector was the first virtual host defined (I.E. the default). VirtualHosts work on the host header sent by the browser, not the DNS records. – Smudge Jul 28 '11 at 14:09
Yes, Apache will pick up the request for the domain, then look for the corresponding virtual host. I do think (not sure 100%) that you can set the CNAME as the root of a domain. As long as there are no A-records as the root. – U4iK_HaZe Jul 28 '11 at 14:13
Okay, I think i got it. They will now enter the IP as their root A record. Unless my local cache is not up to date, It should be working. Thanks for your help. – U4iK_HaZe Jul 28 '11 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.