Tip Site specific error and 404 page

Created: 1 Oct 2021, last update: 30 Jan 2022

Tip: Handling sitecore site specific error and 404 page

Sitecore Tip

In Sitecore 10+ there is a new and easy way to configure a site specific error page. And handling sitecore 404 pages multisite.

Just config it into the <site> definition.
Like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
      <sites>
        <site name="mysite" patch:before="site[@name='website']"
              virtualFolder="/"
              physicalFolder="/"
              rootPath="/sitecore/content/mysite"
              startItem="/home"
              database="web"
              domain="extranet"
              allowDebug="true"
              cacheHtml="true"
              htmlCacheSize="50MB"
              enablePreview="true"
              enableWebEdit="true"
              enableDebugger="true"
              enablePartialHtmlCacheClear="true"
              errorPageUrl="/error?e"
              itemNotFoundUrl="/error?404"
              disableClientData="false"/>
    </sites>
  </sitecore>
</configuration>

Example of site definition patch with errorPageUrl and 404 page, itemNotFoundUrl

You can use this properties:

errorPageUrl: The URL to redirect to, if a generic error occurs.
Default value: if not specified, the value of the ErrorPage setting in the <settings> section is used.

noAccessUrl: The URL to redirect to, if access to an item is denied.
Default value: if not specified, the value of the NoAccessUrl setting in the <settings> section is used.

noLicenseUrl: The URL to redirect to, if a license is missing.
Default value: if not specified, the value of the NoLicenseUrl setting in the <settings> section is used.

layoutNotFoundUrl: The URL to redirect to, if an items layout is not found.
Default value: if not specified, the value of the LayoutNotFoundUrl setting in the <settings> section is used.

itemNotFoundUrl: The URL to redirect to, if an item is not found.
Default value: if not specified, the value of the ItemNotFoundUrl setting in the <settings> section is used.

linkItemNotFoundUrl: The URL to redirect to, if an item being linked to is not found.
Default value: if not specified, the value of the LinkItemNotFoundUrl setting in the <settings> section is used.

noPublishableUrl: The URL of the page that handles errors if no publishable item or version of an item can be found.
Default value: if not specified, the value of the NoPublishableUrl setting in the <settings> section is used.

Very usable for multisite not SXA solutions, before Sitecore 10 you usually build a Pipeline Processor for error and not found page. If your project is upgraded from an older version you also might take a look at this if the logic is simple and easy to replace, use this and simplify your solution.

See: Walkthrough: Configuring a website to require explicit consent for tracking, Option 2: Create site-specific service pages on the Sitecore Documentation website.

For more general Error page and related Sitecore knowledge see Sitecore and the error page writen for Sitecore 6+

Examples of using a pipeline processor for the error pages today only nessary if you have additional wishes, like the way SXA work, SXA lets you set site-specific 404 and 500 pages in a settings item. :

Enable Smart And Safe Error Pages In Sitecore
Better way of handling sitecore 404 pages
Sitecore 404 without 302