You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue 2. When the default locale is not prefixed, the default route doesn't switch the locale back to the default langage
When you don't force a prefix for the default locale, as in this configuration:
shopping:
resource: ../../src/Controller/Application/Shopping/
type: annotation
prefix:
fr: '' # "fr" is the default locale here
en: '/en'
It will give you 2 routes:
/shopping
/en/shopping
Which is the desired behavior. But another bug appears:
if you visit /shopping, the site is in french
if you then go to /en/shopping, the site switches to english
if you then go to /shopping, the site stays in english
Both A and B issues are undesirable (notably from an SEO standpoint):
Issue 1: /shopping is an unwanted duplicate content of /fr/shopping
Issue 2: if the bot that visits the website isn't stateless, it can be served english content on a french page (making it a duplicate too, and unreferencing your french page).
Additional context
When routes are declared using the annotation:
And I thought that declaring a subfolder would override default routing declaration. It does not. So the route is declared twice: once not localized by the configuration named default, which gives /shopping, and once localized in the configuration named shopping, which gives /fr/shopping and /en/shopping
Everything works as expected, both with a prefix for the default locale, or without.
So I guess the issue is more a documentation problem. The exclude configuration parameter is not documented in the Routing section of the documentation (https://symfony.com/doc/5.3/routing.html). Also I stumbled upon the fact that the exclude configuration parameter is not taken into account if the resource parameter does not contain a glob pattern, as mentioned in another issue here: #31587 (comment)
Feel free to close this issue or to attach a documentation label.
Symfony version(s) affected: 5.2.3, but probably any from 4.1.x
Description
Localized routes that are prefixed with a locale prefix encounter a number of issues:
How to reproduce
Say you have a controller method bearing the following annotation:
@Route("/shopping", name="shopping")
Issue 1. When all locales are prefixed, the base route is still accessible
This configuration:
Will give you 3 routes:
/fr/shopping
/en/shopping
/shopping
which is undesiredIssue 2. When the default locale is not prefixed, the default route doesn't switch the locale back to the default langage
When you don't force a prefix for the default locale, as in this configuration:
It will give you 2 routes:
/shopping
/en/shopping
Which is the desired behavior. But another bug appears:
/shopping
, the site is in french/en/shopping
, the site switches to english/shopping
, the site stays in englishBoth A and B issues are undesirable (notably from an SEO standpoint):
/shopping
is an unwanted duplicate content of/fr/shopping
Additional context
When routes are declared using the annotation:
The issue 1 does not exist. There is no
/shopping
route.Same thing goes for a route that wouldn't have the prefix for the default locale:
The issue 2 does not exist. The locale switches correctly back to fr when visiting
/shopping
, as expected.So it seems the issue lies in the way prefixes are implemented.
The text was updated successfully, but these errors were encountered: