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.

Note

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:

  1. 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\.

  2. Go to the providers element inside the linkManager element.

  3. Add two custom link providers, one for always and one for never as in the following example: lpCustomAlways and lpCustomNever.

    Note

    Adding both types is only relevant if you need to configure your sitemaps differently.

  4. For lpCustomAlways, set the languageEmbedding attribute to always.

  5. For lpCustomNever, set the languageEmbedding attribute to never.

    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>
  6. In the Content Editor, navigate to sitecore/Content/[site collection]/[site]/Settings and click the Sitemap item.

  7. 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.

      Specify the custom link provider in the Content Editor
    • To disable language embedding for all languages, enter the name of the custom link provider, where languageEmbedding equals never, for example, lpCustomNever.

  8. To test that language embedding has been configured correctly, publish the site and view the sitemap.

Do you have some feedback for us?

If you have suggestions for improving this article,