我需要我的路由器配置如下工作:
www.bmob.co.uk -> DtCompanyData\Controller\CompanyMap
wage.bmob.co.uk -> DtWage\Controller\Wage
wage.bmob.co.uk/brighton -> DtWage\Controller\WageBrighton
在这里阅读了文档和许多类似的问题之后,我可以使路由工作到子域或子路由,但不能同时工作。
当我有
时// 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,
),
我明白了:
www.bmob.co.uk - works
wage.bmob.co.uk - works
wage.bmob.co.uk/brighton - goes to same page as wage.bmob.co.uk
当我有:
// 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',
),
),
),
),
),
我明白了:
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
我在这里做错了什么?如何让wage.bmob.co.uk和wage.bmob.co.uk/brighton同时工作?感谢。
答案 0 :(得分:2)
我会尝试两种配置:
'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',
),
),
),
),
),
或
'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',
),
),
),
),
),
),
),
编辑:这个怎么样:
'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',
),
),
),
),
),