title: ZF2 and force HTTPS for specific routes
body: <p>I'm trying to achieve forced https when accessing any page under /account route. I've found this question <a href="https://stackoverflow.com/questions/15797599/zf2-toroute-with-https">ZF2 toRoute with https</a> and it works... partially. My routes:</p>
  
  <pre><code>'router' =&gt; array(
      'routes' =&gt; array(
          'account' =&gt; array(
              'type' =&gt; 'Scheme',
              'options' =&gt; array(
                  'route' =&gt; '/account',
                  'scheme' =&gt; 'https',
                  'defaults' =&gt; array(
                      'controller' =&gt; 'Account\Controller\Account',
                      'action' =&gt; 'index',
                  ),
              ),
              'may_terminate' =&gt; true,
              'child_routes' =&gt; array(
                  'default' =&gt; array(
                      'type' =&gt; 'Literal',
                      'options' =&gt; array(
                          'route' =&gt; '/',
                          'defaults' =&gt; array(
                              'controller' =&gt; 'Account\Controller\Account',
                              'action' =&gt; 'index',
                          ),
                      ),
                  ),
                  'signin' =&gt; array(
                      'type' =&gt; 'Segment',
                      'options' =&gt; array(
                          'route' =&gt; '/signin[/:type]',
                          'defaults' =&gt; array(
                              'controller' =&gt; 'Account\Controller\Account',
                              'action' =&gt; 'signin',
                          ),
                          'constraints' =&gt; array(
                              'type' =&gt; '[a-zA-Z][a-zA-Z0-9-_]*',
                          ),
                      ),
                  ),
                  'signout' =&gt; array(
                      'type' =&gt; 'Segment',
                      'options' =&gt; array(
                          'route' =&gt; '/signout',
                          'defaults' =&gt; array(
                              'controller' =&gt; 'Account\Controller\Account',
                              'action' =&gt; 'signout',
                          ),
                      ),
                  ),
                  'register' =&gt; array(
                      'type' =&gt; 'Segment',
                      'options' =&gt; array(
                          'route' =&gt; '/register[/:step]',
                          'defaults' =&gt; array(
                              'controller' =&gt; 'Account\Controller\Account',
                              'action' =&gt; 'register',
                          ),
                          'constraints' =&gt; array(
                              'step' =&gt; '[a-zA-Z][a-zA-Z0-9-_]*',
                          ),
                      ),
                  ),
              ),
          ),
      ),
  ),
  </code></pre>
  
  <p>and a home route from Application module from Skeleton Application (cloned from github). Whenever I access any subroute of /account it throws 404: </p>
  
  <pre><code>http(s)://domain.my/account/signin = 404, wrong
  http(s)://domain.my/account/* = 404, wron
  https://domain.my/signin = signin page, wrong should be /account/signin
  http://domain.my/ = ok, main page
  http://domain.my/account = 404, wrong
  https://domain.my/ = wrong, account page should be main page
  </code></pre>
  
  <p>Generally my problem is: the page should be accessed by http or https BUT /account and it subroutes have to be accessed only by https. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok, I've tried the chained_routes but this is not what I wanted to achieve. I want to do something like this:</p>
  
  <p>User not logged in:
  types:  <a href="http://domain.my/account" rel="nofollow noreferrer">http://domain.my/account</a>  -> redirected to  <a href="https://domain.my/account/login" rel="nofollow noreferrer">https://domain.my/account/login</a>  (I know I can achieve this with <code>$authService-&gt;hasIdentity()</code>) then redirect to  <a href="https://domain.my/account" rel="nofollow noreferrer">https://domain.my/account</a></p>
  
  <p>types:  <a href="http://domain.my/account/login" rel="nofollow noreferrer">http://domain.my/account/login</a>  -> redireted to  <a href="https://domain.my/account/login" rel="nofollow noreferrer">https://domain.my/account/login</a></p>
  
  <p>types:  <a href="http://domain.my/account/edit" rel="nofollow noreferrer">http://domain.my/account/edit</a>  -> redirected to  <a href="https://domain.my/account/login" rel="nofollow noreferrer">https://domain.my/account/login</a>  then to <a href="https://domain.my/account/edit" rel="nofollow noreferrer">https://domain.my/account/edit</a></p>
  
  <p>same with logged user when he access anything from  /account  route it is redirected to the same url but with https. </p>