PS: I'd like to share some relevant information related to site resolving in sxa as an answer.
The site resolution sequence in SXA is important. Many SXA components use SiteInfoResolver
to determine the site, and the results may differ from Sitecore.Context.Site. The resolver verifies the path, language, and internal status
first. If a this match is found it skip check for Context.Site.Name
(in the next statement). It returns the first matching site, regardless of whether it is in a Content Management (CM) or Content Delivery (CD) context - which could be causing your problem.
To implement a quick fix, try modifying the site sequence and unpublish cm-site as answer given above.
If changing the sequence is not possible for any reason, as in my case. You can construct a custom site resolver by overriding public override SiteInfo GetSiteInfo(Item item, Func<SiteInfo, bool> sitesFilter)
.
Replace the default SiteResolver with your own implementation.
<register serviceType="Sitecore.XA.Foundation.Multisite.ISiteInfoResolver, Sitecore.XA.Foundation.Multisite" implementationType="Sitecore.XA.Foundation.Multisite.SiteInfoResolver, Sitecore.XA.Foundation.Multisite" lifetime="Singleton" patch:source="Sitecore.XA.Foundation.Multisite.config"/>
In my case, when I moved CD to the top, all internal links of the CM website were pointing to the CD. However, when I kept CM at the top, Coveo indexes were indexing wrong URLs for CD items (it was taking CM-site urls for CD-site pages).
//Added custom site info logic before existing logic
SiteInfo siteInfoCustom1 = siteInfoArray.FirstOrDefault(s => Context.Site != null && s.Name.Is(Context.Site.Name) && PathMatch(s, item) && LanguagesMatch(s, item) && !s.IsInternal);
if (siteInfoCustom1 != null)
return siteInfoCustom1;
SiteInfo siteInfoCustom2 = siteInfoArray.FirstOrDefault(s => PathMatch(s, item) && LanguagesMatch(s, item) && !s.IsInternal && DatabaseMatch(s, item));
if (siteInfoCustom2 != null)
return siteInfoCustom2;
The first logic siteInfoCustom1
helps to resolve site by matching both item's path and Context.Site. The second siteInfoCustom2
by matching path and database which is for indexing jobs that may run under Sitecore's system SiteContext.
protected bool DatabaseMatch(SiteInfo site, Item item)
{
string siteDatabase = site.Database;
return item.Database.Name.Equals(siteDatabase, StringComparison.InvariantCultureIgnoreCase);
}