title: Apache Virtual Host using mod_vhost_alias
body: <p>I am trying to set up my apache module to dynamically direct all requests to a specific folder and then match the name to a folder of the same name.</p>
  
  <p>To do this I set the following in my <strong>000-default.conf</strong> file in the sites-available folder.</p>
  
  <blockquote>
    <p>UseCanonicalName Off<br>
    VirtualDocumentRoot /var/www/example/%2<br></p>
  </blockquote>
  
  <p>This worked great. </p>
  
  <p>Then I wanted to setup a couple of different domains to not point to the example folder, but somewhere else, so I added a couple of these before the VirtualDocumentRoot  line:</p>
  
  <blockquote>
    <p>&#60;VirtualHost *:80><br>
     ServerName sub1.example.com<br>
     VirtualDocumentRoot /var/www/sub1.example.com<br>
    &#60;/VirtualHost><br></p>
  </blockquote>
  
  <p>However, now the dynamic pointing does not work anymore and all the URL's are redirected to the first  -> VirtualDocumentRoot location.</p>
  
  <p>Can someone please indicate to me what I am doing wrong?</p>
  
  <p>Full Code Example In <strong>apache2/sites-available/000-default.conf</strong>:</p>
  
  <blockquote>
    <p>&#60;VirtualHost *:80><br>
     ServerName sub1.example.com<br>
     VirtualDocumentRoot /var/www/sub1.example.com<br>
    &#60;/VirtualHost><br></p>
    
    <p>&#60;VirtualHost *:80><br>
     ServerName sub2.example.com<br>
     VirtualDocumentRoot /var/www/sub2.example.com<br>
    &#60;/VirtualHost><br></p>
    
    <p>&#60;VirtualHost *:80><br>
     ServerName sub3.example.com<br>
     VirtualDocumentRoot /var/www/sub3.example.com<br>
    &#60;/VirtualHost><br></p>
    
    <p>UseCanonicalName Off<br>
    VirtualDocumentRoot /var/www/example/%2<br></p>
  </blockquote>