Avoid duplicate url segment in the brands page
Based on this support ticket: https://support.optimizely.com/hc/en-us/requests/1804446, We’ve identified an issue with multilingual sites where the URLs returned by the api/v2/content/PageByUrl endpoint include an extra /fr/ segment.
Example:
English URL:
/brands/kalas/catalog/wire-and-cable/automotive-wire-and-cable
French URL returned by API:
/fr/brands/kalas/fr/catalog/wire-and-cable/automotive-wire-and-cable
As you can see, the fr segment is duplicated.
Translation Dictionary Configuration:
CatalogUrlRoot = fr/catalog
BrandUrlRoot = fr/brands
Observed behavior:
When navigating to a catalog under a brand, the system adds the language segment twice.
Analysis:
We reviewed the source code and found that the issue seems to be in the PathBuilderUtilities.cs class, specifically in the GetCatalogRootPath method:
var languageId = language?.Id ?? SiteContext.Current.LanguageDto?.Id;
This logic always builds the URL with the language prefix from the current SiteContext, which works correctly for standalone catalog pages. However, when the catalog is under a brand, another method has already appended the language segment. As a result, the language prefix (fr) is added again, causing the duplicated segment in the final URL.
Expected behavior:
The method should include a fallback or validation to check whether the language segment is already present in the URL before adding it again. Also, we'd like to customize this piece of code if you don't want to change it. Currently, it is not possible to customize it.
Thanks,
Polo Jiménez