You can use a specific type of router with the name "Hostname" (class "Zend \ Mvc \ Router \ Http \ Hostname"). Here is a simple example:
'router' => array(
'routes' => array(
'example1' => array(
'type' => 'Hostname',
'options' => array(
'route' => ':subdomain.mydomain.com',
'constraints' => array(
'subdomain' => 'mysubdomain1',
),
'defaults' => array(
'controller' => 'MyModule1\Controller\MyFirstController',
'action' => 'index',
),
),
),
'example2' => array(
'type' => 'Hostname',
'options' => array(
'route' => ':subdomain.mydomain.com',
'constraints' => array(
'subdomain' => 'mysubdomain2',
),
'defaults' => array(
'controller' => 'MyModule2\Controller\MySecondController',
'action' => 'index',
),
),
),
),
),
I would probably split this configuration into two parts: "example1" in the configuration of my first module and "example2" in the configuration of my second module.
You will find complete information about this type of router and others on this page .
source
share