title: Symfony2 secure all subdomains
body: <p>I'm creating application in Symfony with dynamic subdomains.</p>
  
  <p>I would like to secure every subdomain expect the www (the www is less important).</p>
  
  <p>For example : foo.mydomain.com redirects to foo.mydomain.com/login </p>
  
  <p>but mydomain.com shouldn't been redirected.</p>
  
  <p>In the <code>VHost</code> I have this line : </p>
  
  <pre><code>ServerAlias : *.mydomain.com
  </code></pre>
  
  <p>I'm using the FOSUserBundle for managing users with a custom UserManager. </p>
  
  <p>The firewall looks like this :</p>
  
  <pre><code>firewalls:
      fos:
          pattern: ^/
          host: ^\.mydomain.com
          form_login:
              provider: fos_userbundle
              csrf_provider: form.csrf_provider
              use_referer:                    true
          logout:       true
          anonymous:    ~
  
      main:
          pattern: ^/
          form_login:
              provider: fos_userbundle
              csrf_provider: form.csrf_provider
              use_referer:                    true
          logout:       true
          anonymous:    true
  </code></pre>
  
  <p>I'm not sure if I should have two firewalls or not</p>
  
  <p>The access control looks like this :</p>
  
  <pre><code>access_control:
      - { path: ^/login,  roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { host: ^\.mydomain.com, path: ^/, roles: ROLE_USER }
  </code></pre>
  
  <p>So I need something like *.mydomain.com with roles ROLE_USER</p>