在routing.yml中你可以执行以下操作:
redirect_old_url_to_new:
pattern: /old-pattern
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-pattern
permanent: true
这将重定向网址/old-pattern
to /new-pattern
。但是,如果我有一个参数,如何在新路径中翻译该参数,例如:
redirect_old_url_to_new:
pattern: /old-pattern/{page}
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-pattern/{page}
permanent: true
这不起作用,将重定向到/new-pattern/{page}
从字面上看,因此将重定向自/old-pattern/23
to /new-pattern/{page}
.
如果参数名相同,则自动传递参数:
FirstRoute:
pattern: /firstroute/{page}
defaults:
_controller: Bundle:Controller:action
# SecondRoute will redirect to FirstRoute.
# ex: /secondroute/1 redirects to /firstroute/1
SecondRoute:
pattern: /secondroute/{page}
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: FirstRoute
permanent: true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)