Enable or disable language codes in sitemap URLs
If your pages exist in different languages, consider whether you want the URLs written to the sitemap to contain language codes. Adding language codes helps the search engines determine the language of a page. This means that internet users are more likely to find relevant content in their preferred language.
You configure language embedding for each site.
You can configure this feature in the following ways:
-
Default - pages in all languages, except for the default language, get a language code.
-
Always - pages in all languages get a language code.
-
Never - regardless of the language, no page gets a language code.
To enable or disable language codes in the sitemap:
-
Open the
Sitecore.XA.Foundation.Multisite.config
file. The path to the directory on the server might look as follows:\App_Config\Modules\SXA\Foundation\
. -
Go to the
providers
element inside thelinkManager
element. -
Add two custom link providers, one for always and one for never as in the following example:
lpCustomAlways
andlpCustomNever
.NoteAdding both types is only relevant if you need to configure your sitemaps differently.
-
For
lpCustomAlways
, set thelanguageEmbedding
attribute toalways
. -
For
lpCustomNever
, set thelanguageEmbedding
attribute tonever
.Code example:
RequestResponse<providers> <add name="switchableLinkProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.SwitchableLinkProvider, Sitecore.XA.Foundation.Multisite"/> <add name="localizedProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false"/> <add name="lpCustomAlways" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" shortenUrls="true" useDisplayName="false"/> <add name="lpCustomNever" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false"/> </providers>
-
In the Content Editor, navigate to sitecore/Content/[site collection]/[site]/Settings and click the Sitemap item.
-
In the URL options section, in the Link provider name field, do one of the following:
-
To use the default setting, leave the field empty.
-
To enable language embedding for all languages, enter the name of the custom link provider, where languageEmbedding equals
always
, for example,lpCustomAlways
. -
To disable language embedding for all languages, enter the name of the custom link provider, where languageEmbedding equals
never
, for example,lpCustomNever
.
-
-
To test that language embedding has been configured correctly, publish the site and view the sitemap.