Zend Framework 2 - Multiple subdomains create problems
I am writing an application in Zend Framework 2 that will run from several different subdomains, and I want to have a different module for each subdomain to keep things in order.
My problem is when I add more than 1 subdomain to the routing it loses one of the subdomains.
For example: this setting works testbed.localhost (module / app) a.testbed.localhost (module / A)
If I add an additional one, it will route all requests for a to the app index controller
e.g. testbed.localhost (module / application), a.testbed.localhost (module / A), b.testbed.localhost (module / B)
This is the .config.php module for the / A module
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'a.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'A\Controller',
'controller' => 'A\Controller\A',
'action' => 'index',
),
),
And this is the route to module.config.php in module / B
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'b.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'B\Controller',
'controller' => 'B\Controller\B',
'action' => 'index',
),
),
Now the namespaces are correct in the module.config.php files, I noticed that the a.testbed.localhost subdomain will work if I remove the reference to it from config / application.config.php
<?php
return array(
'modules' => array(
'Application',
'A',
'B', <--- A doesn't work if B is here
),
And if I swap A and B around in the modules array above, then B will be redirected to Application Module and A will work. So it seems to be having more than one subdomain problem. Anyone got any ideas / came across the same thing?
source to share