How to configure a redirect to another route without a custom controllerEdit this page
Warning: You are browsing the documentation for Symfony 2.1, which is no longer maintained.
Read the updated version of this page for Symfony 6.0 (the current stable version).
This guide explains how to configure a redirect from one route to another without using a custom controller.
Assume that there is no useful default controller for the
/ path of
your application and you want to redirect these requests to
Your configuration will look like this:
1 2 3 4 5 6 7 8 9 10 11
AppBundle: resource: "@App/Controller/" type: annotation prefix: /app root: pattern: / defaults: _controller: FrameworkBundle:Redirect:urlRedirect path: /app permanent: true
In this example, you configure a route for the
/ path and let RedirectController
handle it. This controller comes standard with Symfony and offers two actions
for redirecting request:
urlRedirectredirects to another path. You must provide the
pathparameter containing the path of the resource you want to redirect to.
redirect(not shown here) redirects to another route. You must provide the
routeparameter with the name of the route you want to redirect to.
permanent switch tells both methods to issue a 301 HTTP status code
instead of the default
302 status code.