title: How do you map a sub domain to a webapp on Tomcat 6 (including the root webapp)?
body: <p>subject says it all. What I want is to map each sub domain to a webapp like:</p>
  
  <pre><code>http://root.domain.com:8080 -&gt; http://domain.com:8080/
  http://manager.domain.com:8080 -&gt; http://domain.com:8080/manager
  http://abc.domain.com:8080 -&gt; http://domain.com:8080/abc
  http://def.domain.com:8080 -&gt; http://domain.com:8080/def
  </code></pre>
  
  <p>on a localhost machine this would be</p>
  
  <pre><code>http://root.localhost:8080 -&gt; http://localhost:8080/
  http://manager.localhost:8080 -&gt; http://localhost:8080/manager
  http://abc.localhost:8080 -&gt; http://localhost:8080/abc
  http://def.localhost:8080 -&gt; http://localhost:8080/def
  </code></pre>
  
  <p>Ideally, I'd like to use port 80 instead of 8080, but that's another story. I'd be happy to get it going with port 8080 at first, so that the path at the end of the URL disappears.</p>
  
  <p>Note, the arrows aren't redirects but what I'd enter if I left Tomcat as is.</p>
  
  <p>I know the Tomcat docs page <a href="http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html" rel="nofollow noreferrer">http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html</a>. I've read it many times, but didn't make much progress. I edited etc/hosts to add 127.0.0.1 bbstats.localhost. I then added</p>
  
  <pre><code>&lt;Host name="bbstats.localhost" appBase="webapps/bbstats"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false"&gt;
  &lt;/Host&gt;
  </code></pre>
  
  <p>to Tomcat's server.xml in the conf dir. My webapp's context.xml is:</p>
  
  <pre><code>&lt;Context path="/bbstats" docBase="bbstats" debug="5" reloadable="true" crossContext="true"&gt; 
  &lt;/Context&gt;
  </code></pre>
  
  <p>Restart Tomcat. Redploy via Ant. When entering</p>
  
  <p><a href="http://bbstats.localhost:8080/" rel="nofollow noreferrer">http://bbstats.localhost:8080/</a></p>
  
  <p>into a browser, I get a blank screen.</p>
  
  <p>When using appBase="webapps" instead of appBase="webapps/bbstats", I get to Tomcat's root app. The latter behavior is kind of expected. But how do I make bbstats.localhost:8080 go to the bbstats webapp without a trailing /bbstats in the URL?</p>