Sitecore Multisite, Part 4: Cross-Site Links

This (short) blog post contains information about linking between multiple logical sites managed by a single instance of the Sitecore ASP.NET web Content management System (CMS) and Customer Engagement Platform (CEP).

If CMS users create links between managed sites, you need to ensure that your solution uses the correct hostnames when rendering those links. You have at least two types of links to consider: those in Rich Text Editor (RTE) fields, and those in other types of fields (for example, an item selected in a Droplink field).

For RTE fields, Sitecore uses the renderField pipeline to expand dynamic links created by users, which (depending on configuration) can add the protocol and hostname to the URL. For RTE fields, one approach to include the correct hostname would be to require CMS users to enter the URLs of other sites as external links rather than internal links, but this would defeat some usability and link management features of Sitecore. You would probably need a separate solution for other types of fields, and both types of fields might as well use the same solution.

For links that you generate with code, you can use the same APIs used by the renderField pipeline to retrieve item URLs, which eventually invoke methods in the link provider. In your code, you can affect those results before they render to the page. Instead of writing that code where you generate links, you can configure or override the link provider, which would address links that you generate with code as well as those processed by the renderField pipeline.

The Rendering.SiteResolving setting controls whether the link provider attempts to determine a managed site associated with each linked item and include the hostName associated with that site in the link. If the hostName contains a wildcard (*) or a pipe separator (|) (which you would not want in URLs), the site definition can specify the targetHostName attribute; if present, the link provider uses targetHostName instead of the hostName.

In some cases, Sitecore may not respect the Rendering.SiteResolving setting. You may need to explicitly specify that the LinkProvider should resolve sites by passing an option to the appropriate methods. The LinkProvider override on Sitecore Marketplace can apply the Rendering.SiteResolving setting in such cases even in cases where you do not specify it.