从Symfony2中的routing.yml将一条路由重定向(301)到另一条路由 [英] Redirect (301) one route to another from routing.yml in Symfony2
本文介绍了从Symfony2中的routing.yml将一条路由重定向(301)到另一条路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这可能微不足道,但是我无法在网络上或Symfony2参考中找到任何内容。
I know this is probably trivial, but I couldn't find anything on the web or in the Symfony2 reference.
如何将一条路线从另一条路线重定向到另一条路线routing.yml(带有301状态代码)?
How do I redirect one route to another from routing.yml (with 301 status code)?
我正在寻找类似这样的内容:
I'm looking for something like this:
SomeRoute:
pattern: /someroute
defaults: { _controller: SomeBundle:Controller:action }
AnotherRoute:
pattern: /anotherroute
defaults: { _redirect: {route: SomeRoute, status: 301} }
I可以创建一个控制器,但似乎有点过头了,因为我没有任何参数(即使要按原样传递它们,也会过头)。
I could create a controller, but it seems overkill, since I don't have any parameters (and it would be overkill even so, if they are to be passed as they are).
推荐答案
SomeRoute:
pattern: /someroute
defaults:
_controller: SomeBundle:Controller:action
AnotherRoute:
pattern: /anotherroute
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: SomeRoute
permanent: true # this is for 301
page: 5 # you can pass additional attributes
这篇关于从Symfony2中的routing.yml将一条路由重定向(301)到另一条路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文