1

We have a SXA website and tried to add 404 page as described here Setup 404 page by creating the Pipeline and adding a rendering to set the StatusCode to 404.

We also added Page Not found link in Settings

enter image description here

Testing that in our Azure environment but it didn't work.The returned status code is still 200.

Is it any other best way to configure the 404 page for SXA website?

Thanks.

4 Answers 4

6

The Pipeline solution is for the core Sitecore or non-SXA sites.

In SXA you can set the pages directly by putting/selecting the pages with its out of the box feature. This is how you do it.

  • Create the page/pages for not found and internal server error page, you can even style it as per you design.

  • Assign those page in your settings, by selecting the relevant pages.

enter image description here

  • For the 500 page you have to do a little trick, once you have designed the pages completely.
    1. go to /sitecore/content/{Environment}/{DemoSXASite}/Settings/Site Grouping/DemoSXASite
    2. Select the tab from top navigation "ERROR HANDLING"
    3. Click on Generate static page.

enter image description here

Here is my blog link for reference:

https://isaadansari.wordpress.com/2018/07/04/setting-up-the-not-found-and-internal-server-error-pages-with-sxa-how-to-implement-series/

4
  • Hi @Sam are you sure that using this configuration the returned statuscode it's 404 and not 200? Tried that I still have the issue, look at my response below
    – user1032
    Commented Jul 5, 2018 at 12:20
  • Did you publish the complete website after setting up the settings I suggested. Feel free to Ping me on slack, if you need any help Commented Jul 5, 2018 at 19:42
  • Hi @Sam I got the issue, the out of the box processor Sitecore.XA.Feature.ErrorHandling.Pipelines.HtpRequestProcessed.SetStatusCode was deleting in a patch done by the team. I revert that and it works fine now.Thanks
    – user1032
    Commented Aug 24, 2018 at 16:41
  • Glad, it worked. (Y) Commented Aug 24, 2018 at 17:50
1

thank you for this article. I Created a 404 page as you mentioned and added some component to customize content displayed. I disabled the processor to override Sitecore's default 404. I set also ItemNotFoundUrl <setting name="ItemNotFoundUrl" value="/404" /> In web.config I didn't added any specific configuration in section customErrors and httpErrors for 404 statutscode just added paths in httpErrors for 400,405 and 500 statuscode.

Added 404 and 500 in Settings

enter image description here Trying that I still got 200 statuscode

Stilling have the issue, I added also a controller rendering to set statusCode

public class PageNotFoundController : Controller
{
    public ActionResult Request404Page()
    {
        System.Web.HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        System.Web.HttpContext.Current.Response.StatusCode = 404;
        System.Web.HttpContext.Current.Response.StatusDescription = "404 File Not Found";

        return View();
    }
}

and the the view is empty

But testing that still have the issue 200 statuscode returned. Any ideas?

1
0

Not sure if this is the best way but if the redirect is already working but the status code is incorrect you could add a view rendering with these three lines of code to your 404 page(I have tested in Azure).

@{
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.NotFound;
HttpContext.Current.Response.StatusDescription = "Page not found";
}
0

In addition to Sitecore Sam's answer, you need to set this in your config so that the correct status code is shown.

<setting name="RequestErrors.UseServerSideRedirect" value="true" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.