@@ -43,9 +43,8 @@ action to redirect to this new url:
43
43
# or
44
44
homepage :
45
45
path : /
46
- url_redirect : /app
47
- defaults :
48
- permanent : true
46
+ redirect_to_url : /app
47
+ permanent : true
49
48
50
49
.. code-block :: xml
51
50
@@ -68,9 +67,7 @@ action to redirect to this new url:
68
67
</route >
69
68
70
69
<!-- 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" />
74
71
</routes >
75
72
76
73
.. code-block :: php
@@ -94,15 +91,112 @@ action to redirect to this new url:
94
91
])
95
92
;
96
93
97
- // or
98
- $routes->urlRedirect ('homepage', '/', '/app)
94
+ // or, with namespace Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator
95
+ $routes->redirectToUrl ('homepage', '/', '/app)
99
96
->permanent(true)
100
97
;
101
98
};
102
99
103
100
.. versionadded :: 4.3
104
101
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\B undle\F rameworkBundle\C ontroller\R edirectController::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\B undle\F rameworkBundle\C ontroller\R edirectController::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\C omponent\R outing\L oader\C onfigurator;
169
+
170
+ use Symfony\B undle\F rameworkBundle\C ontroller\R edirectController;
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\B undle\F rameworkBundle\R outing\L oader\C onfigurator;
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
+ };
106
200
107
201
In this example, you configured a route for the ``/ `` path and let the
108
202
``RedirectController `` redirect it to ``/app ``. The ``permanent `` switch
@@ -139,10 +233,9 @@ action:
139
233
# or
140
234
admin :
141
235
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
146
239
147
240
.. code-block :: xml
148
241
@@ -166,10 +259,10 @@ action:
166
259
</route >
167
260
168
261
<!-- 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 " / >
173
266
</routes >
174
267
175
268
.. code-block :: php
@@ -192,16 +285,113 @@ action:
192
285
])
193
286
;
194
287
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')
197
290
->permanent(true)
198
291
->keepQueryParams(true)
199
292
;
200
293
};
201
294
202
295
.. versionadded :: 4.3
203
296
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\B undle\F rameworkBundle\C ontroller\R edirectController::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\B undle\F rameworkBundle\C ontroller\R edirectController::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\C omponent\R outing\L oader\C onfigurator;
365
+
366
+ use Symfony\B undle\F rameworkBundle\C ontroller\R edirectController;
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\B undle\F rameworkBundle\R outing\L oader\C onfigurator;
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
+ };
205
395
206
396
.. caution ::
207
397
@@ -238,18 +428,15 @@ permanent redirects use ``308`` code instead of ``301``:
238
428
legacy_foo :
239
429
path : /legacy/foo
240
430
url_redirect : /foo
241
- defaults :
242
- permanent : true
243
- keepRequestMethod : true
431
+ permanent : true
432
+ keep_request_method : true
244
433
245
434
# redirects with the 307 status code
246
435
route_bar :
247
436
path : /bar
248
437
url_redirect : /tmp/bar
249
- defaults :
250
- # ...
251
- permanent : false
252
- keepRequestMethod : true
438
+ permanent : false
439
+ keepRequest_method : true
253
440
254
441
.. code-block :: xml
255
442
@@ -261,16 +448,18 @@ permanent redirects use ``308`` code instead of ``301``:
261
448
http://symfony.com/schema/routing/routing-1.0.xsd" >
262
449
263
450
<!-- 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" />
268
456
269
457
<!-- 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" />
274
463
</routes >
275
464
276
465
.. code-block :: php
@@ -280,14 +469,13 @@ permanent redirects use ``308`` code instead of ``301``:
280
469
281
470
return function (RoutingConfigurator $routes) {
282
471
// redirects with the 308 status code
283
- $routes->urlRedirect ('legacy_foo', '/legacy/foo', '/foo')
472
+ $routes->redirectToUrl ('legacy_foo', '/legacy/foo', '/foo')
284
473
->permanent(true)
285
474
->keepRequestMethod(true)
286
475
;
287
476
288
477
// 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')
291
479
->keepRequestMethod(true)
292
480
;
293
481
};
0 commit comments