The business may want to use a short and precise url in their commercial or in their advertising material, instead of the long url, represing a content item living in fourth level in our Sitecore structure. In this blog I explain how Sitecore aliases can help us doing this, and also why we should be careful using Sitecore aliases.
How to setup an alias
- Login in to Sitecore and navigate to Sitecore/system/aliases
- Create a new alias item. Name it MyCampaign
- Let the alias item point to a content item by clicking “Insert Link” and then choose the content item.
- Verify that domain/mycapaign resolves to the selected content item in your browser
How do aliases work
Sitecore item resolves to a content item, so there is no redirect involved.
The alias is being resolved directly, so the url stays the same. The response code is 200 like on any other valid request. Sitecore item resolver works in a way, where it first checks if there is an alias matching the url.
If there is an alias with the string, that goes right after the domain name, the Sitecore resolver will use that alias, and resolve to the item that the alias is pointing to.
Because Sitecore first checks for an alias, the same alias will work for all the websites, hosted on the specific Sitecore instance. That is important to remember.
You need to use aliases cautiously. You may only have one website on the Sitecore instance, when doing the alias, but later on there could be a new website created on the same instance, and if you are unlucky, there may also be a url on any new website, that matches the alias. The end user could then experience an error, when browsing the new website, as the Sitecore item resolver will match the alias, and try to resolve it to a content item, which lives in another domain/website, than the one the user is currently on. If you already have a Sitecore instance with several websites, you can imagine the complexity of ensuring a specific alias name, is only used on the relevant website. Of course it is more difficult the more generic the alias name is. So my message is: consider when to use aliases and when to use redirects instead.
Another point for considering if an alias is the right solutions, is that by the use of aliases you are serving the same content on the same url. Google will see it as duplicate content, so you may also be punished from a SEO perspective.