child_routes 时 ZF2 错误 404
ZF2 error 404 when child_routes
这是我最后的机会了。我试着寻找答案,但说真的,我看不出我做错了什么......
我正在尝试在网站上设置多域。
使用文字路由时一切正常。
使用主机名路由添加其他域时,仍然可以。
但是当向该主机名路由添加 child_routes 时,父路由会发出 404。
这是我的 module.config :
'resources' => $resources,
'router' => array(
'routes' => array(
'example.com' => array(
'type' => 'Zend\Mvc\Router\Http\Hostname',
'options' => array(
'route' => '[:subdomain.]:domain.:tld', // domain levels from right to left
'contraints' => array(
'subdomain' => 'www',
'domain' => 'example',
'tld' => 'com',
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'itdoc',
),
),
'may_terminate' => true,
'child_routes' => array(
'customCatalog2' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/custom-catalog',
'defaults' => array(
'action' => 'customCatalog',
),
),
),
访问 http://example.com 时,我收到 404。
但是子路线工作正常(http://example.com/custom-catalog)
但是如果我注释掉child_routes(和may_terminate),我可以访问根域
你知道我的代码有什么问题吗?
谢谢!!!
我测试了你的代码,事实上这很奇怪,但经过一些测试和阅读文档后我发现了。
This documentaiton help
^
我很期待这个组件,并在文档中找到了这个:
'packages.zendframework.com' => array(
'type' => 'Zend\Mvc\Router\Http\Hostname',
'options' => array(
'route' => ':4th.[:3rd.]:2nd.:1st', // domain levels from right to left
'contraints' => array(
'4th' => 'packages',
'3rd' => '.*?', // optional 3rd level domain such as .ci, .dev or .test
'2nd' => 'zendframework',
'1st' => 'com',
),
// Purposely omit default controller and action
// to let the child routes control the route match
),
// child route controllers may span multiple modules as desired
'child_routes' => array(
'index' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Package\Controller\Index',
'action' = > 'index',
),
),
'may_terminate' => true,
),
),
),
如您所见,它们有子路由,但声明的第一个路由是匹配此模式的路由:'/'
,这是您的主路由,您必须将其声明为下面的代码:
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'itdoc',
),
之后,你的主路由是正确的,你可以继续其他子路由,只是主机名不是实际的主路由'/'
。
这是我最后的机会了。我试着寻找答案,但说真的,我看不出我做错了什么...... 我正在尝试在网站上设置多域。 使用文字路由时一切正常。 使用主机名路由添加其他域时,仍然可以。 但是当向该主机名路由添加 child_routes 时,父路由会发出 404。 这是我的 module.config :
'resources' => $resources,
'router' => array(
'routes' => array(
'example.com' => array(
'type' => 'Zend\Mvc\Router\Http\Hostname',
'options' => array(
'route' => '[:subdomain.]:domain.:tld', // domain levels from right to left
'contraints' => array(
'subdomain' => 'www',
'domain' => 'example',
'tld' => 'com',
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'itdoc',
),
),
'may_terminate' => true,
'child_routes' => array(
'customCatalog2' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/custom-catalog',
'defaults' => array(
'action' => 'customCatalog',
),
),
),
访问 http://example.com 时,我收到 404。 但是子路线工作正常(http://example.com/custom-catalog) 但是如果我注释掉child_routes(和may_terminate),我可以访问根域
你知道我的代码有什么问题吗?
谢谢!!!
我测试了你的代码,事实上这很奇怪,但经过一些测试和阅读文档后我发现了。
This documentaiton help ^ 我很期待这个组件,并在文档中找到了这个:
'packages.zendframework.com' => array(
'type' => 'Zend\Mvc\Router\Http\Hostname',
'options' => array(
'route' => ':4th.[:3rd.]:2nd.:1st', // domain levels from right to left
'contraints' => array(
'4th' => 'packages',
'3rd' => '.*?', // optional 3rd level domain such as .ci, .dev or .test
'2nd' => 'zendframework',
'1st' => 'com',
),
// Purposely omit default controller and action
// to let the child routes control the route match
),
// child route controllers may span multiple modules as desired
'child_routes' => array(
'index' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Package\Controller\Index',
'action' = > 'index',
),
),
'may_terminate' => true,
),
),
),
如您所见,它们有子路由,但声明的第一个路由是匹配此模式的路由:'/'
,这是您的主路由,您必须将其声明为下面的代码:
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'itdoc',
),
之后,你的主路由是正确的,你可以继续其他子路由,只是主机名不是实际的主路由'/'
。