Question

I need my router configuration to work as follows:

www.bmob.co.uk           -> DtCompanyData\Controller\CompanyMap   
wage.bmob.co.uk          -> DtWage\Controller\Wage  
wage.bmob.co.uk/brighton -> DtWage\Controller\WageBrighton  

After reading the documentation and many similar questions on here, I can get the routing to work either for the subdomain, or for the child routes, but not both at the same time.

When I have

// In Application/config/module.config.php:

'home' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'www.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtCompanyData\Controller',
            'controller' => 'DtCompanyData\Controller\CompanyMap',
            'action' => 'index',
        ),
    ),
),

// In DtWage/config/module.config.php:

'wage' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'wage.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtWage\Controller',
            'controller' => 'DtWage\Controller\Wage',
            'action' => 'index',
        ),
    ),
    'may_terminate' => true,
),

I get:

www.bmob.co.uk - works  
wage.bmob.co.uk - works  
wage.bmob.co.uk/brighton - goes to same page as wage.bmob.co.uk

When I have:

// In Application/config/module.config.php:

'home' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'www.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtCompanyData\Controller',
            'controller' => 'DtCompanyData\Controller\CompanyMap',
            'action' => 'index',
        ),
    ),
),

// In DtWage/config/module.config.php:

'wage' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'wage.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtWage\Controller',
            'controller' => 'DtWage\Controller\Wage',
            'action' => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'wagebrighton' => array( 
            'type' => 'literal',
            'options' => array(
                'route' => '/brighton',
                'defaults' => array(
                    '__NAMESPACE__' => 'DtWage\Controller',   // Have also tried without this line, same result
                    'controller' => 'DtWage\Controller\WageBrighton',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

I get:

www.bmob.co.uk - works  
wage.bmob.co.uk - 404 The requested URL could not be matched by routing.  
wage.bmob.co.uk/brighton - works

What am I doing wrong here? How to I get wage.bmob.co.uk and wage.bmob.co.uk/brighton to both work at the same time? Thanks.

Was it helpful?

Solution

I would try two configurations :

'wage' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'wage.bmob.co.uk/',
        'defaults' => array(
            '__NAMESPACE__' => 'DtWage\Controller',
            'controller' => 'DtWage\Controller\Wage',
            'action' => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'wagebrighton' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/brighton',
                'defaults' => array(
                    '__NAMESPACE__' => 'DtWage\Controller', // Have also tried without this line, same result
                    'controller' => 'DtWage\Controller\WageBrighton',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

or

'wage' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'wage.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtWage\Controller',
        ),
    ),
    'may_terminate' => false,
    'child_routes' => array(
        'wagehome' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/',
                'defaults' => array(
                    '__NAMESPACE__' => 'DtWage\Controller',
                    'controller' => 'DtWage\Controller\Wage',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'wagebrighton' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => '/brighton',
                        'defaults' => array(
                            '__NAMESPACE__' => 'DtWage\Controller',
                            'controller' => 'DtWage\Controller\WageBrighton',
                            'action' => 'index',
                        ),
                    ),
                ),
            ),
        ),
    ),
),

EDIT : what about this one :

'wage' => array(
    'type' => 'hostname',
    'options' => array(
        'route' => 'wage.bmob.co.uk',
        'defaults' => array(
            '__NAMESPACE__' => 'DtWage\Controller',
        ),
    ),
    'may_terminate' => false,
    'child_routes' => array(
        'wagehome' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/',
                'defaults' => array(
                    '__NAMESPACE__' => 'DtWage\Controller',
                    'controller' => 'DtWage\Controller\Wage',
                    'action' => 'index',
                ),
            ),
        ),
        'wagebrighton' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/brighton',
                'defaults' => array(
                    '__NAMESPACE__' => 'DtWage\Controller',
                    'controller' => 'DtWage\Controller\WageBrighton',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top