How to configure site-specific aliases
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.
- Some aliases might need to be configured to work only with certain sites.
- Different sites might need to have aliases with the same name pointing to different site-specific items.
This article describes how to customize aliases functionality to introduce site-specific aliases.
To implement site-specific aliases proceed as follows:
- 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.
- 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:
This allows aliases placed under the site folders to only be applied to the corresponding Sitecore sites.
- 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.
- If there is a need to create global aliases that would work for all sites, place the corresponding alias items under each site folder.
- After the customization above, only aliases placed under the site folders are resolved.
- To allow selecting all child items of the /sitecore/content node using the Linked Item field, do the following:
- Navigate to the /sitecore/templates/System/Alias template.
- Change the Source value of the Linked Item field to /sitecore/content.