Yuriy
Yuriy

Reputation: 163

How I can to create a custom page for error code 404?

Could you tell me please, how I can do it in Sitecore? I'm beginner in Sitecore and I need understand how I can do it step by step. May be you know any instruction, video or articles about it?

Thank you for your help!

Upvotes: 0

Views: 1285

Answers (2)

Surendra Singh
Surendra Singh

Reputation: 299

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.

Upvotes: 1

Dave Goosem
Dave Goosem

Reputation: 568

You can have both standard .NET error pages configured within the web.config (recommened you use transforms to modify your web.config)

<system.webServer>       
    <httpErrors xdt:Transform="Remove" />
    <httpErrors errorMode="DetailedLocalOnly">
        <remove statusCode="404" subStatusCode="-1" />
        <remove statusCode="500" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="404.html" responseMode="File" />
        <error statusCode="500" prefixLanguageFilePath="" path="Error.html" responseMode="File" />
    </httpErrors>

You can also then configure sitecore to set custom error pages by patching the following Sitecore config settings:

<configuration>
    <sitecore>
     <settings>            
        <setting name="RequestErrors.UseServerSideRedirect">
            <patch:attribute name="value">true</patch:attribute>
        </setting>
        <setting name="ItemNotFoundUrl">
            <patch:attribute name="value">/Error/404</patch:attribute>
        </setting>
        <setting name="LayoutNotFoundUrl">
            <patch:attribute name="value">/Error/404</patch:attribute>
        </setting>
        <setting name="LinkItemNotFoundUrl">
            <patch:attribute name="value">/Error/404</patch:attribute>
        </setting>
        <setting name="NoAccessUrl">
            <patch:attribute name="value">/Error.aspx</patch:attribute>
        </setting>
      </settings>
    </sitecore>
</configuration>

The one you're looking for is the ItemNotFoundUrl which as long as you set to a legitimate Sitecore Url (so a content page for your 404) you can then have a content managed page for when the error can be handled by Sitecore.

Upvotes: 1

Related Questions