title: rewrite subdomain to direcory in same server
body: <p>I have a domain, lets say <strong>mydomain.com</strong>.</p>
  
  <p>I want every subdomain of this to load the contents of the directory with the same name... For example, if someone writes </p>
  
  <p><a href="http://sub.mydomain.com/index.php" rel="nofollow">http://sub.mydomain.com/index.php</a></p>
  
  <p>I want to show him the contents of </p>
  
  <p><a href="http://sub.mydomain.com/sub/index.php" rel="nofollow">http://sub.mydomain.com/sub/index.php</a></p>
  
  <p>Still, I want it to show in the addressbar the <a href="http://sub.mydomain.com/index.php" rel="nofollow">http://sub.mydomain.com/index.php</a> </p>
  
  <p>The apache vhost is like </p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
    ServerName *.mydomain.com
    DocumentRoot /var/www/vhosts/mydomain.com/subdomains/subs/www
    ... more stuff ...
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>so in the filesystem, the files for the example above would be under the directory </p>
  
  <p>/var/www/vhosts/mydomain.com/subdomains/subs/www/sub</p>
  
  <p>I tried many of the proposed solutions here, but most of them were redirects to some other domain/subdomain or end up in a redirect loop :(</p>
  
  <p>tia</p>