我有一个 Symfony 4.2 站点,它在两个子域上提供内容:
a.example.com
b.example.com
我怎样才能重定向的请求/resetting/reset/
就a
到b
,同时保持查询字符串?
我尝试了下面的但它没有做任何事情 - 即当我点击a.example.com/resetting/reset
它时它只是停留在那里。没有错误。
resetting:
host: ^%a_domain%$
path: ^/resetting/reset/
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
defaults:
path: '%b_domain%/resetting/reset/'
permanent: true
keepQueryParams: true
任何想法,将不胜感激!
我无法使用 yaml 方法,因此我使用自定义重定向操作覆盖了路由,如下所示:
/**
* @Route("/resetting/reset/{token}",
* name="fos_user_resetting_reset_override",
* host="{domain}",
* defaults={"domain"="%a_domain%"},
* requirements={"domain"="(%a_domain%)"},
* )
*/
public function redirectResettingRouteToBDomain(string $token): RedirectResponse
{
// generate the current url with an absolute path
$path = $this->generateUrl(
'fos_user_resetting_reset',
['token' => $token],
UrlGeneratorInterface::ABSOLUTE_PATH
);
// replace A_DOMAIN with B_DOMAIN in the path
$domain = preg_replace(
'/' . preg_quote(getenv('A_DOMAIN'), '/') . '/',
getenv('B_DOMAIN'),
$this->getRequest()->server->get('HTTP_HOST')
);
// ensure the redirect works on http and https
$url = '//' . $domain . $path;
return $this->redirect($url);
}
请注意,我为A_DOMAIN
and设置了 env vars B_DOMAIN
,然后将它们作为a_domain
和b_domain
参数使用。
本质上,上面的控制器操作仅在 上触发A_DOMAIN
,覆盖 的默认fos_user_resetting_reset
路由B_DOMAIN
,然后重定向请求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句