title: vhost rewrite rules in apache - get rid of the subdomain without redirecting
body: <p>I know similar questions have been asked, but for the life of me I can't seem to make it work.</p>
  
  <p>The idea is to rewrite the subdomain as part of the url. We also want the request to be handled by the server without making remote calls, and the url in the client to not be re-written. </p>
  
  <p>To put it simply:
  <code>http://test.example.com/(something)</code> should be interpreted as <code>http://example.com/test/(something)</code></p>
  
  <p>'something' is optional. </p>
  
  <p>I've tried a done of different solutions, but never seem to get it quite right - this is my first experience with that.</p>
  
  <pre><code>#   RewriteEngine on 
  #   RewriteCond %{HTTP_HOST} ^test.example.com [NC]
  #   RewriteRule ^((?!test/).*)$ /test/$1 [L,NC]
  
  #   RewriteCond %{HTTP_HOST} ^test\.example\.com$ [NC] 
  #   RewriteRule ^(.*)$  "test%{REQUEST_URI}" 
  #   RewriteRule ^(.*)$ test/$1 [L]  
  
  #RewriteEngine on 
  #RewriteCond %{HTTP_HOST} ^test.example.com [NC]
  #RewriteRule ^(.*)$ example.com/test/%{REQUEST_URI} [P,L,NC]
  </code></pre>
  
  <p>It is important to know that <code>example.com/test/something</code> already exists on a different server and should NOT be used or called. </p>
  
  <p>My thinking was to redirect <code>test.example.com</code> to the new server and then interpret it on the new server as <code>example.com/test</code> by using another vhost (the whole application is being developped without subdomains, but we are going to migrate part by part using subdomains, until we manage to migrate everything and restore the 'normal' way).</p>
  
  <p>In time, we will have sub1.example.com, sub2.example.com, etc. Aliases might play a role here, but I'm out of my depth. </p>
  
  <p>Thanks for the help!</p>