views:

701

answers:

2

I have a application with dynamic subdomains that should be redirected to different servers depending on a part of the subdomain.

Example (anything means whateveryouwant, a dynamic name):

example.com --> server1
anything.example.com --> server1
a.example.com --> server2
b.example.com --> server1
a.anything.example.com --> server2
b.anything.example.com --> server1
anything.a.example.com --> server2
anything.b.example.com --> server1
a.anything.a.example.com --> server2
b.anything.a.example.com --> server2

I guess this is not possible to do with standard dns configuration. So instead I'm planning to point *.example.com to server1 and the configure apache to forward the request to server2 when it matches any of the criterias. Problem is that I don't know how to config apache for this. Does anyone have an idea of where to start?

+1  A: 

Sure you can do it in DNS. Just create A records for example.com., anything.example.com., b.example.com., etc. that all have the IP of server 1, and similarly for the domains you want on server 2. Of course, you'll still have to configure virtual hosts for the various domains on each server, but you won't need to do any redirecting from one server to the other.

David Zaslavsky
A: 

With "anything" i meant a dynamic name, like the usernames of the users of the application. So I can not make a dns record for each one of these, it could be millions.

Martin
It all depends on your DNS server software. If it has appropriate wild card support, you don't need an infinite number of records.
Martin v. Löwis
Okay. I'm unfortunately not able to control the DNS software so I think I'm gonna need a apache solution anyway.
Martin
Or can I setup my own DNS software on server1 and let all traffic from the domain registrars DNS go to server1?
Martin