29

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

lemon24
  • 329
  • 1
  • 3
  • 6

1 Answers1

71
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
Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133