6

We have two sites www.site1.com and www.site2.com. We are having problem when trying to create cross site relative links in RTE field.

For example. In RTE field of site2 site, if we insert a relative link of an item related to site1 site, it doesn’t resolve the proper URL according to site1 URL customization. For example, item having Physical Path as Sitecore/Home/Site1/Global Content/Profiles/A/Adam, is being resolved as www.site1.com/adam. But when we use this item in site2 as a relative link it doesn’t resolve the URL.

In config, we also have configured two different sites.

Please suggest what can be possible issue?

14

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

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.