title: Symfony2 Routing - route subdomains
body: <p>Is there a way to set up hostname based routing in <strong>Symfony2</strong>?  </p>
  
  <p>I didn't find anything about this topic in the official documentation.<br>
  <a href="http://symfony.com/doc/2.0/book/routing.html" rel="noreferrer">http://symfony.com/doc/2.0/book/routing.html</a></p>
  
  <p>I want to route the request based on the given hostname:<br>
  foo.example.com<br>
  bar.example.com<br>
  {{subdomain}}.example.com</p>
  
  <p>So in essence, the controller would get the current subdomain passed as a parameter.</p>
  
  <p>Similar to the Zend solution:<br>
  <a href="http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname" rel="noreferrer">http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname</a></p>
  
  <pre><code>$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
      ':username.users.example.com',
      array(
          'controller' =&gt; 'profile',
          'action'     =&gt; 'userinfo'
      )
  );
  $plainPathRoute = new Zend_Controller_Router_Route_Static('');
  
  $router-&gt;addRoute('user', $hostnameRoute-&gt;chain($plainPathRoute));
  </code></pre>
  
  <p>I hope that it's possible and I just missed it somehow.<br>
  Thanks in advance!</p>