How to configure site-specific aliases


Description

Sitecore has aliases functionality to configure multiple website URLs to access any content item. For more details about aliases, refer to Sitecore documentation.

By default, alias configuration is shared between all Sitecore sites in the Sitecore XP solution. In some scenarios, it might, however, be required to configure site-specific aliases. For example:

This article describes how to customize the 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 only as a starting point:
    • 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 names of the sites that require support for site-specific aliases. For example, the items hierarchy might look like the following:
    sitecore
    --system
    ----aliases
    ------website
    ------website2
    ------website3
    
    This allows aliases placed under the site folders to be applied only to the corresponding Sitecore sites.
  3. Create alias items under the corresponding site folder manually. Alternatively, use the Aliases dialog box from the Presentation tab, 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: