How to configure site-specific aliases


Description

Sitecore XP implements Aliases functionality to allow configuration of multiple website URLs to access any content item.

For more details about aliases, refer to Data Definition API Cookbook.

By default, alias configuration is shared between all Sitecore sites from a Sitecore XP solution.

In some scenarios, it might, however, be required to configure site-specific aliases.

For example:

This article describes how to customize aliases functionality to introduce site-specific aliases.

Solution

To implement site-specific aliases proceed as follows:

  1. Replace the default AliasResolver processor of the httpRequestBegin pipeline with the custom one that takes into account the context site name when resolving aliases. The following code samples are provided as a starting point only:
    • For Sitecore XP 9.0.2 and earlier, use the AliasResolver.
    • For Sitecore XP 9.1.0 and later, use the AliasResolver.
      Note that these code samples might require some modification depending on your Sitecore XP version.
  2. Under the /sitecore/system/Aliases item, create folders with the name of the sites that require support for site-specific aliases. Check the site names in the <sites> section of the web.config file.
    For example, items hierarchy might look like the following:
    sitecore
    --system
    ----aliases
    ------website
    ------website2
    ------website3
    
    This allows aliases placed under the site folders to only be applied to the corresponding Sitecore sites.
  3. Create alias items under the corresponding site folder manually. Alternatively, use Aliases dialog from the Presentation ribbon, while always adding the <websiteName>/ prefix before the actual alias name when using this dialog.
  4. If there is a need to create global aliases that would work for all sites, place the corresponding alias items under each site folder.

Notes: