Skip to content

Commit 0020a8b

Browse files
author
Jules Pietri
committed
fixup config
1 parent 455bec3 commit 0020a8b

File tree

2 files changed

+324
-59
lines changed

2 files changed

+324
-59
lines changed

routing/redirect_in_config.rst

Lines changed: 226 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ action to redirect to this new url:
4343
# or
4444
homepage:
4545
path: /
46-
url_redirect: /app
47-
defaults:
48-
permanent: true
46+
redirect_to_url: /app
47+
permanent: true
4948
5049
.. code-block:: xml
5150
@@ -68,9 +67,7 @@ action to redirect to this new url:
6867
</route>
6968
7069
<!-- or -->
71-
<route id="homepage" path="/" url-redirect="/app">
72-
<default key="permanent">true</default>
73-
</route>
70+
<route id="homepage" path="/" redirect-to-url="/app" permanent="true" />
7471
</routes>
7572
7673
.. code-block:: php
@@ -94,15 +91,112 @@ action to redirect to this new url:
9491
])
9592
;
9693
97-
// or
98-
$routes->urlRedirect('homepage', '/', '/app)
94+
// or, with namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator
95+
$routes->redirectToUrl('homepage', '/', '/app)
9996
->permanent(true)
10097
;
10198
};
10299
103100
.. versionadded:: 4.3
104101

105-
The "url redirect" shortcut has been introduced in Symfony 4.3.
102+
The "redirect to url" shortcut has been introduced in Symfony 4.3.
103+
Using it enables new options as well:
104+
105+
.. configuration-block::
106+
107+
.. code-block:: yaml
108+
109+
# config/routes.yaml
110+
111+
# before
112+
legacy:
113+
path: /legacy
114+
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
115+
defaults:
116+
path: /new-url
117+
permanent: true
118+
scheme: http
119+
httpPort: 8080
120+
httpsPort: 4443
121+
keepRequestMethod: true
122+
# ... standard options
123+
124+
# after
125+
legacy:
126+
path: /legacy
127+
redirect_to_url: /new-url
128+
permanent: true
129+
scheme: http
130+
http_port: 8080
131+
https_port: 4443
132+
keep_request_method: true
133+
# ... standard options
134+
135+
.. code-block:: xml
136+
137+
<!-- config/routes.yaml -->
138+
139+
<!-- before -->
140+
<route id="legacy" path="/legacy" controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
141+
<default key="path">/new-url</default>
142+
<default key="permanent">true</default>
143+
<default key="scheme">http</default>
144+
<default key="httpPort">8080</default>
145+
<default key="httpsPort">4443</default>
146+
<default key="keepRequestMethod">true</default>
147+
<!-- ... standard options -->
148+
</route>
149+
150+
<!-- after -->
151+
<route id="legacy"
152+
path="/legacy"
153+
redirect-to-url="/new-url"
154+
permanent="true"
155+
scheme="http"
156+
http-port="8080"
157+
https-port="4443"
158+
keep-request-method="true" />
159+
<!-- ... standard options -->
160+
</route>
161+
162+
.. code-block:: php
163+
164+
<?php
165+
// config/routes.php
166+
167+
// before
168+
namespace Symfony\Component\Routing\Loader\Configurator;
169+
170+
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
171+
172+
return function (RoutingConfigurator $routes) {
173+
$routes->add('legacy', '/legacy')
174+
->controller([RedirectController::class, 'urlRedirectAction'])
175+
->defaults([
176+
'path' => '/new-url',
177+
'permanent' => true,
178+
'scheme' => 'http,
179+
'httpPort' => 8080,
180+
'httpsPort' => 4443,
181+
'keepRequestMethod' => true,
182+
])
183+
// ... standard options
184+
;
185+
};
186+
187+
// after, using new namespace
188+
namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
189+
190+
return function (RoutingConfigurator $routes) {
191+
$routes->redirectToUrl('legacy', '/legacy', '/new/url')
192+
->permanent(true)
193+
->scheme('http')
194+
->httpPort(8080)
195+
->httpsPort(4443)
196+
->keepRequestMethod(true)
197+
// ... standard options
198+
;
199+
};
106200

107201
In this example, you configured a route for the ``/`` path and let the
108202
``RedirectController`` redirect it to ``/app``. The ``permanent`` switch
@@ -139,10 +233,9 @@ action:
139233
# or
140234
admin:
141235
path: /wp-admin
142-
redirect: sonata_admin_dashboard
143-
defaults:
144-
permanent: true
145-
keepQueryParams: true
236+
redirect_to: sonata_admin_dashboard
237+
permanent: true
238+
keepQueryParams: true
146239
147240
.. code-block:: xml
148241
@@ -166,10 +259,10 @@ action:
166259
</route>
167260
168261
<!-- or -->
169-
<route id="admin" path="/wp-admin" redirect="sonata_admin_dashboard">
170-
<default key="permanent">true</default>
171-
<default key="keepQueryParams">true</default>
172-
</route>
262+
<route id="admin"
263+
path="/wp-admin" redirect-to="sonata_admin_dashboard"
264+
permanent="true"
265+
keepQueryParams="true" />
173266
</routes>
174267
175268
.. code-block:: php
@@ -192,16 +285,113 @@ action:
192285
])
193286
;
194287
195-
// or
196-
$routes->redirect('admin', '/wp-admin', 'sonata_admin_dashboard')
288+
// or, with namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator
289+
$routes->redirectTo('admin', '/wp-admin', 'sonata_admin_dashboard')
197290
->permanent(true)
198291
->keepQueryParams(true)
199292
;
200293
};
201294
202295
.. versionadded:: 4.3
203296

204-
The ``redirect`` shortcut has been introduced in Symfony 4.3.
297+
The ``redirect to`` shortcut has been introduced in Symfony 4.3.
298+
Using it enables new options as well:
299+
300+
.. configuration-block::
301+
302+
.. code-block:: yaml
303+
304+
# config/routes.yaml
305+
306+
# before
307+
legacy:
308+
path: /legacy
309+
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
310+
defaults:
311+
route: app_new
312+
permanent: true
313+
ignoreAttributes: [attr, ibutes]
314+
keepRequestMethod: true
315+
keepQueryParams: true
316+
# ... standard options
317+
318+
# after
319+
legacy:
320+
path: /legacy
321+
redirect_to: app_new
322+
permanent: true
323+
ignore_attributes: [attr, ibutes]
324+
keep_request_method: true
325+
keep_query_params: true
326+
# ... standard options
327+
328+
.. code-block:: xml
329+
330+
<!-- config/routes.yaml -->
331+
332+
<!-- before -->
333+
<route id="legacy" path="/legacy" controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction">
334+
<default key="route">app_new</default>
335+
<default key="permanent">true</default>
336+
<default key="ignoreAttributes">
337+
<list>
338+
<string>attr</string>
339+
<string>ibutes</string>
340+
</list>
341+
</default>
342+
<default key="keepRequestMethod">true</default>
343+
<default key="keepQueryParams">true</default>
344+
<!-- ... standard options -->
345+
</route>
346+
347+
<!-- after -->
348+
<route id="legacy"
349+
path="/legacy"
350+
redirect-to="app_new"
351+
permanent="true"
352+
ignore-attributes="attr, ibutes"
353+
keep-request-method="true"
354+
keep-query-params="true" />
355+
<!-- ... standard options -->
356+
</route>
357+
358+
.. code-block:: php
359+
360+
<?php
361+
// config/routes.php
362+
363+
// before
364+
namespace Symfony\Component\Routing\Loader\Configurator;
365+
366+
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
367+
368+
return function (RoutingConfigurator $routes) {
369+
$routes->add('legacy', '/legacy')
370+
->controller([RedirectController::class, 'redirectAction'])
371+
->defaults([
372+
'route' => 'app_new',
373+
'permanent' => true,
374+
'ignoreAttributes' => [attr, ibutes],
375+
'keepRequestMethod' => true,
376+
'keepQueryParams' => true,
377+
])
378+
// ... standard options
379+
;
380+
};
381+
382+
// after
383+
// new namespace
384+
namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator;
385+
386+
return function (RoutingConfigurator $routes) {
387+
$routes->redirectTo('legacy', '/legacy', 'app_new')
388+
->permanent(true)
389+
->ignoreAttributes([attr, ibutes])
390+
->keepRequestMethod(true)
391+
->keepQueryParams(true)
392+
// ... standard options
393+
;
394+
};
205395

206396
.. caution::
207397

@@ -238,18 +428,15 @@ permanent redirects use ``308`` code instead of ``301``:
238428
legacy_foo:
239429
path: /legacy/foo
240430
url_redirect: /foo
241-
defaults:
242-
permanent: true
243-
keepRequestMethod: true
431+
permanent: true
432+
keep_request_method: true
244433
245434
# redirects with the 307 status code
246435
route_bar:
247436
path: /bar
248437
url_redirect: /tmp/bar
249-
defaults:
250-
# ...
251-
permanent: false
252-
keepRequestMethod: true
438+
permanent: false
439+
keepRequest_method: true
253440
254441
.. code-block:: xml
255442
@@ -261,16 +448,18 @@ permanent redirects use ``308`` code instead of ``301``:
261448
http://symfony.com/schema/routing/routing-1.0.xsd">
262449
263450
<!-- redirects with the 308 status code -->
264-
<route id="legacy_foo" path="/legacy/foo" url-redirect="/foo">
265-
<default key="permanent">true</default>
266-
<default key="keepRequestMethod">true</default>
267-
</route>
451+
<route id="legacy_foo"
452+
path="/legacy/foo"
453+
url-redirect="/foo"
454+
permanent="true"
455+
keep-request-method="true" />
268456
269457
<!-- redirects with the 307 status code -->
270-
<route id="route_bar" path="/bar" url-redirect="/tmp/bar">
271-
<default key="permanent">false</default>
272-
<default key="keepRequestMethod">true</default>
273-
</route>
458+
<route id="route_bar"
459+
path="/bar"
460+
url-redirect="/tmp/bar"
461+
permanent="false"
462+
keep-request-method="true" />
274463
</routes>
275464
276465
.. code-block:: php
@@ -280,14 +469,13 @@ permanent redirects use ``308`` code instead of ``301``:
280469
281470
return function (RoutingConfigurator $routes) {
282471
// redirects with the 308 status code
283-
$routes->urlRedirect('legacy_foo', '/legacy/foo', '/foo')
472+
$routes->redirectToUrl('legacy_foo', '/legacy/foo', '/foo')
284473
->permanent(true)
285474
->keepRequestMethod(true)
286475
;
287476
288477
// redirects with the 307 status code
289-
$routes->urlRedirect('route_bar', '/bar', '/tpm/bar')
290-
->permanent(false)
478+
$routes->redirectToUrl('route_bar', '/bar', '/tpm/bar')
291479
->keepRequestMethod(true)
292480
;
293481
};

0 commit comments

Comments
 (0)