Configure 404 Not Found Page in SXA

as easy as ....

(Photo by Erik Mclean on Unsplash)

A nice and commonly used feature in SXA is the "not found" functionality. Sadly here is no from A-Z documentation and SXA defaults collide a bit with Sitecore defaults. So let's walk through setting up a Not Found Page as intended by general requirements.

Overview

1. Create a Page Template (otpional but better authoring UX)

2. Create a page

3. Configure page to be the not found page

4. Configure sitecore to use server side redirects 

 

0. Preconditions:

You have sitecore installed with SXA Module

You have a tenant and a site created

Make sure that you have installed the out of the box "Error Handling" Module to your tenant. This one makes sure to see Error Handling fields on your settings item. In Appendix at the bottom you can find a detailed description how to check it.

 

1. Create a Page Template (otpional but better authoring UX)

Actually you can make any page your Error Page but it could be benefitial to create your own page template for Error pages:

1. Navigate to: /sitecore/templates/Project/[YourTenantFolder]/[YourTenant]

2. Duplicate Page Template and call it "Error Pages"

3. Set Icon of the template 

4. In Standard Values set "Change frequency" of Sitemap Settings to "do not include" to have error pages removed from sitemap.xml 

Do not include in Sitemap

5. As Error pages are not supposed to be in any of your Navigations you can check Navigation filters on standard values.

Navigation Filters

2. Create a page

 Create a page using either the general page template or the "error page" template created in step 1

Add the content that you require to tell your visitors that the page they have searched for is not existend (anymore). 

3. Configure page to be the "not found page"

Navigate to: sitecore/content/[your_tenant]/[your_site]/Settings

Find the field "Page Not Found Link"

Note: Make sure that you have installed the out of the box "Error Handling" Module to your tenant. This one makes sure to see Error Handling fields on your settings item. In Appendix at the bottom you can find a detailed description how to check it.

 

Select the page created in step 2 

Setting Not Found Page for your site

 

4. Configure sitecore to use server side redirects 

Now when you leave it until here, the configured page is shown in case the url cannot be resolved to an actual page. But when you take a closer look to the network activities you can see that there is a 302 redirect to the 404 page. And the Not Found page is returned with a http statuts code 200. This can lead to SEO penalties.

Sadly a configuration in sitecore.config is not set fitting to that purpose as default.

You need to set the RequestErrors.UseServerSideRedirect to true (sitecore default is false) 

1. ideally you create a patch file e.g. here: C:\inetpub\wwwroot\[your_instance]\App_Config\Include\z.Feature.Overrides 

2. name the file e.g.: z.Sandbox.NotFound.config

3. Put in the following content:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<settings>
<setting name="RequestErrors.UseServerSideRedirect" set:value="true"/>
</settings>
</sitecore>
</configuration>

4. When saving the file, your application will restart.

5. To test if config has been overwritten correctly call showconfig.aspx on your sitecore instance https://your-sitecore-instance/sitecore/admin/showconfig.aspx

Search for the config name "RequestErrors.UseServerSideRedirect"

5. Test the functionality

1. Open Browser and it's developer Tools

2. Select the Network Tab  of Developer Tools

3. Request a path under your Hostname that does not belong to a page e.g. https://yoursite.local/abc

You should see your 404 Page and in Network Tab of Developer Tools you'll see that it's deliverd with http response code 404

 

Test Not Found Page

 

Appendix

Error Handling Module

To check if the Error Handling Module that is shipped with SXA is installed to your tenant you can check it in 2 ways:

Check Settings Item

1. Go to Settings Item of your site

2. Scroll down to "Error Handling" Section

3. If section is there, everything is good. If not, read further ;-)

Check installed Modules 

1. Navigate to your tenant

2. Check the "Modules" field and see if Module "Error Handling Tenant Setup" is in the List. if not continue reading ;-)

Error Handling Module 

Install Module

1. Navigate to your tenant item

2. do a right Mouseclick

3. Select "Scripts --> Add Tenant Module" from context menu

Note Found Error Handling

4. Select "Error Handling" Module from checklist and Click OK button. Module will get installed.

Error Handling Module

  To test if installation was successful check the Settings item again for the "Error Handling" section

Created: 3.12.2020

SXA Go Live Checklist