title: Apache: Redirect dynamic subdomains to different ip's
body: <p>I have a application with dynamic subdomains that should be redirected to different servers depending on a part of the subdomain.</p>
  
  <p>Example (anything means whateveryouwant, a dynamic name):</p>
  
  <pre><code>example.com --&gt; server1
  anything.example.com --&gt; server1
  a.example.com --&gt; server2
  b.example.com --&gt; server1
  a.anything.example.com --&gt; server2
  b.anything.example.com --&gt; server1
  anything.a.example.com --&gt; server2
  anything.b.example.com --&gt; server1
  a.anything.a.example.com --&gt; server2
  b.anything.a.example.com --&gt; server2
  </code></pre>
  
  <p>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?</p>