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