Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 392
lemon24 Avatar asked Dec 16 '11 02:12

lemon24


1 Answers

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 
like image 189
Elnur Abdurrakhimov Avatar answered Oct 07 '22 11:10

Elnur Abdurrakhimov