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">
<CacheExpiration>30</CacheExpiration>
</processor>
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.