Sitecore 8.2.7 SXA 1.7

Our website does not render the language in the urls, however the sitemap does. Is there a way to ensure that SXA generates the urls like it does for the navigation?

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <xhtml:link rel="alternate" hreflang="en" href="https://www.company.com/en" />


Sitecore support acknowledged this as a bug. May be slated for SXA 1.8.

  • as far I remember this is a known bug. which sxa version do you have. Jun 12 '18 at 18:58
  • 1
    Still an issue in SXA 1.8 Feb 7 '19 at 1:12
  • Actually scratch that it's not an issue in 1.8 - the <loc> is correct, it just also adds the alternate hreflang even if you only have one language. Feb 7 '19 at 5:23

I had the same problem, it appears that the SitemapHandler doesn't always obey the langaugeEmbedding option set in in the configuration. I think the problem is in the ResolveLanguageEmbedding function in the LocalizableLinkProvider.

Replace the SitemapHandler

To fix this, I simply overrode the SXA SitemapHandler and overrode this method:

protected virtual UrlOptions GetUrlOptions()
    UrlOptions defaultUrlOptions = LinkManager.GetDefaultUrlOptions();
    SiteContext site = Context.Site;
    defaultUrlOptions.Site = site;
    int num1 = 0;
    defaultUrlOptions.AlwaysIncludeServerUrl = num1 != 0;
    int num2 = 1;
    defaultUrlOptions.SiteResolving = num2 != 0;
    return defaultUrlOptions;

So that it would either be hard coded to set the required languageEmbedding or you can manually read the link provider settings and make sure it is set correctly.

To override the SitemapHandler, replace this processor with your patch:

<processor type="Sitecore.XA.Feature.SiteMetadata.Pipelines.HttpRequestBegin.SitemapHandler, Sitecore.XA.Feature.SiteMetadata" resolve="true" patch:source="Sitecore.XA.Feature.SiteMetadata.config">

Replace the LinkProvider

We also had to replace the SXA LocalizableLinkProvider and override the GetItemUrl method:

public override string GetItemUrl(Item item, UrlOptions options)
    if (options.LanguageEmbedding == LanguageEmbedding.AsNeeded)
        options.LanguageEmbedding = this.LanguageEmbedding;

    return base.GetItemUrl(item, options);

We did this because the LanguageEmbedding value in the options passed in had different values to the settings in the configuration which caused the language to be embedded for some SXA controls and not others. This sanitized that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.