29
votes

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

1 Answers

71
votes
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