Redirect (301) one route to another from routing.yml in Symfony2

十年热恋 提交于 2019-12-17 21:48:13

问题


I know this is probably trivial, but I couldn't find anything on the web or in the Symfony2 reference.

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 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).


回答1:


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


来源:https://stackoverflow.com/questions/8529038/redirect-301-one-route-to-another-from-routing-yml-in-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!