Creating a custom 404 Page in Sitecore

Nobody wants to see the standard Sitecore 404 page. Thankfully it’s really easy to change the error pages a user is redirected to through some config settings.

Your error pages can be pages in Sitecore or static HTML files. For 404 pages I would normally use a Sitecore page, that way content authors can still manage its content. For an Error Page I would recommend a static html file to avoid issues with the Error page potentially error-ing.

Add these to a patch file and update the urls accordingly:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <!--  ITEM NOT FOUND HANDLER
            Url of page handling 'Item not found' errors
      -->
      <setting name="ItemNotFoundUrl">
        <patch:attribute name="value">/ErrorPages/404.html</patch:attribute>
      </setting>
      <!--  LINK ITEM NOT FOUND HANDLER
            Url of page handling 'Link item not found' errors
      -->
      <setting name="LinkItemNotFoundUrl">
        <patch:attribute name="value">/ErrorPages/404.html</patch:attribute>
      </setting>
      <!--  LAYOUT NOT FOUND HANDLER
            Url of page handling 'Layout not found' errors
      -->
      <setting name="LayoutNotFoundUrl">
        <patch:attribute name="value">/ErrorPages/404.html</patch:attribute>
      </setting>
      <!--  ERROR HANDLER
            Url of page handling generic errors
      -->
       <setting name="ErrorPage">
        <patch:attribute name="value">/ErrorPages/Error.html</patch:attribute>
      </setting>
    </settings>
  </sitecore>
</configuration>


These settings are already defined in the web.config file and changing them here will have the same effect, but I recommend adding patch config files as it will make your solution easier to update in the future.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s