How to configure a redirect to another route without a custom controller
How to configure a redirect to another route without a custom controller¶
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
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.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.