Skip to content

Documented the trailing_slash_on_root option #9490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions routing/external_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ suppose you want to prefix all application routes with ``/site`` (e.g.
The path of each route being loaded from the new routing resource will now
be prefixed with the string ``/site``.

.. note::

If any of the prefixed routes defines an empty path, Symfony adds a trailing
slash to it. In the previous example, an empty path prefixed with ``/site``
will result in the ``/site/`` URL. If you want to avoid this behavior, set
the ``trailing_slash_on_root`` option to ``false``:

.. configuration-block::

.. code-block:: yaml

# config/routes.yaml
controllers:
resource: '../src/Controller/'
type: annotation
prefix: /site
trailing_slash_on_root: false

.. code-block:: xml

<!-- config/routes.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<import
resource="../src/Controller/"
type="annotation"
prefix="/site"
trailing-slash-on-root="false" />
</routes>

.. code-block:: php

// config/routes.php
use Symfony\Component\Routing\RouteCollection;

$app = $loader->import('../src/Controller/', 'annotation');
// the second argument is the $trailingSlashOnRoot option
$app->addPrefix('/site', false);
// ...

.. versionadded:: 4.1
The ``trailing_slash_on_root`` option was introduced in Symfony 4.1.

Prefixing the Names of Imported Routes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down