@@ -487,6 +487,30 @@ that are special: each adds a unique piece of functionality inside your applicat
487
487
``_locale ``
488
488
Used to set the locale on the request (:ref: `read more <translation-locale-url >`).
489
489
490
+ Redirecting URLs with Trailing Slashes
491
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
492
+
493
+ Historically, URLs have followed the UNIX convention of adding trailing slashes
494
+ for directories (e.g. ``https://example.com/foo/ ``) and removing them to refer
495
+ to files (``https://example.com/foo ``). Although serving different contents for
496
+ both URLs is OK, nowadays it's common to treat both URLs as the same URL and
497
+ redirect between them.
498
+
499
+ Symfony follows this logic to redirect between URLs with and without trailing
500
+ slashes (but only for ``GET `` and ``HEAD `` requests):
501
+
502
+ ---------- ---------------------------------------- ------------------------------------------
503
+ Route path If the requested URL is ``/foo `` If the requested URL is ``/foo/ ``
504
+ ---------- ---------------------------------------- ------------------------------------------
505
+ ``/foo `` It matches (``200 `` status response) It doesn't match (``404 `` status response)
506
+ ``/foo/ `` It makes a ``301 `` redirect to ``/foo/ `` It matches (``200 `` status response)
507
+ ---------- ---------------------------------------- ------------------------------------------
508
+
509
+ In summary, adding a trailing slash in the route path is the best way to ensure
510
+ that both URLs work. Read the :doc: `/routing/redirect_trailing_slash ` article to
511
+ learn how to avoid the ``404 `` error when the request URL contains a trailing
512
+ slash and the route path does not.
513
+
490
514
.. index ::
491
515
single: Routing; Controllers
492
516
single: Controller; String naming format
0 commit comments