我试图在访问 /account 路由下的任何页面时实现强制 https。我发现这个问题ZF2 toRoute with https并且它可以工作......部分。我的路线:
'router' => array(
'routes' => array(
'account' => array(
'type' => 'Scheme',
'options' => array(
'route' => '/account',
'scheme' => 'https',
'defaults' => array(
'controller' => 'Account\Controller\Account',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Account\Controller\Account',
'action' => 'index',
),
),
),
'signin' => array(
'type' => 'Segment',
'options' => array(
'route' => '/signin[/:type]',
'defaults' => array(
'controller' => 'Account\Controller\Account',
'action' => 'signin',
),
'constraints' => array(
'type' => '[a-zA-Z][a-zA-Z0-9-_]*',
),
),
),
'signout' => array(
'type' => 'Segment',
'options' => array(
'route' => '/signout',
'defaults' => array(
'controller' => 'Account\Controller\Account',
'action' => 'signout',
),
),
),
'register' => array(
'type' => 'Segment',
'options' => array(
'route' => '/register[/:step]',
'defaults' => array(
'controller' => 'Account\Controller\Account',
'action' => 'register',
),
'constraints' => array(
'step' => '[a-zA-Z][a-zA-Z0-9-_]*',
),
),
),
),
),
),
),
以及来自 Skeleton Application 的 Application 模块的主路由(从 github 克隆)。每当我访问 /account 的任何子路由时,它都会抛出 404:
http(s)://domain.my/account/signin = 404, wrong
http(s)://domain.my/account/* = 404, wron
https://domain.my/signin = signin page, wrong should be /account/signin
http://domain.my/ = ok, main page
http://domain.my/account = 404, wrong
https://domain.my/ = wrong, account page should be main page
通常我的问题是:该页面应该通过 http 或 https 但 /account 访问,并且它的子路由只能通过 https 访问。
编辑
好的,我已经尝试了 chained_routes 但这不是我想要实现的。我想做这样的事情:
用户未登录:类型: http ://domain.my/account -> 重定向到 https://domain.my/account/login (我知道我可以使用 实现此目的$authService->hasIdentity()
)然后重定向到 https://domain.my /帐户
类型: http ://domain.my/account/login -> 重定向到 https://domain.my/account/login
类型: http ://domain.my/account/edit -> 重定向到 https://domain.my/account/login 然后到https://domain.my/account/edit
与登录用户相同,当他从 /account 路由访问任何内容时,它将被重定向到相同的 url,但使用 https。