In the routing.yml you can do things like:
redirect_old_url_to_new:
pattern: /old-pattern
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-pattern
permanent: true
Which will redirect the url /old-pattern
to /new-pattern
. However, if I have a parameter, how can the parameter be translated in the new path, e.g.:
redirect_old_url_to_new:
pattern: /old-pattern/{page}
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /new-pattern/{page}
permanent: true
This is NOT working and will redirect to /new-pattern/{page}
literally and will therefore redirect from /old-pattern/23
to /new-pattern/{page}
.
If the parameter name is identical, then the parameter will be passed automatically:
FirstRoute:
pattern: /firstroute/{page}
defaults:
_controller: Bundle:Controller:action
# SecondRoute will redirect to FirstRoute.
# ex: /secondroute/1 redirects to /firstroute/1
SecondRoute:
pattern: /secondroute/{page}
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: FirstRoute
permanent: true
Seems like there is a mistake in Symfony's Book
root:
pattern: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app
permanent: true
As Arms said, it's "FrameworkBundle:Redirect:redirect" and not "FrameworkBundle:Redirect:urlRedirect"
I was wrong earlier, this works for me :
redirection:
path: /exercices.html
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: blog
slug: url-of-the-post
permanent: true
Put directly parameter_name: parameter_value
under route
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With