This is a pretty common business-case in Sitecore multi-site projects, and fortunately there is pretty good support for cross-site links OOTB. If what you need isn't available OOTB or if it isn't working the way that you want then it's pretty straight-forward and low-effort to customize the solution to your needs. See below for details:
Enabling SiteResolving
for your Solution
Make sure that in your config, you have the Rendering.SiteResolving
setting enabled. It should look like the below:
<setting name="Rendering.SiteResolving" value="true" />
This setting tells Sitecore that it should try to resolve the correct site for the links that you enter, including in the RTE fields.
Matching and Resolving hostName
and targetHostName
In addition, if you are doing any wildcard (*) or pipe (|) matches on the hostName
attributes of your <site>
configuration nodes, then make sure that you specify the targetHostName
of each site, or else Sitecore will not be able to resolve the correct host name (without the asterisk wildcard) to add to the link.
In your case, you might have something like the following:
<site name="site1" hostName="*site1.com" targetHostName="www.site1.com" ... />
<site name="site2" hostName="www.site2.com|site2.com" targetHostName="www.site1.com" ... />
Forcing the LinkProvider
to Respect Rendering.SiteResolving
Note that in some cases, Sitecore may not respect the value of the Rendering.SiteResolving
setting, and may require modifications to the LinkProvider
in order to get it working.
For example, the following (untested) code from Paul Martin's blog post (linked below) can be used to force the LinkProvider
to respect the SiteResolving
setting for all GetItemUrl
calls:
public class LinkProvider : Sitecore.Links.LinkProvider
{
public override string GetItemUrl(Item item, UrlOptions options)
{
string itemUrl;
//other code
options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;
itemUrl = base.GetItemUrl(item, options);
//other code
return itemUrl;
}
}
Additional Information