Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arun 141 posts 404 karma points
    May 20, 2021 @ 12:08
    Arun
    0

    Different error pages based on root

    Can we set multiple 404 pages in the same site? enter image description here

    Suppose I have different root nodes like this and i need to set different 404 pages based on the ancestor root node.
    for eg, if i try mysite.com/sales/non-existing-page then i should redirect to the 404 page set for sales. Similar mechanism for all other root nodes.
    Is it possible or is there is any way?
    Any help is appreciated

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    May 20, 2021 @ 19:07
    Marc Goodson
    0

    Hi Arun

    Yes it is, when a request comes into Umbraco, there is a pipeline of different 'ContentFinder's' that fire one after another in a queue, trying to match the incoming request to a content item in Umbraco.

    and then the last one in the queue is called the 'LastChanceContentFinder'

    https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder#notfoundhandlers

    The cool thing is you can create your own ContentFinder by implementing the interface IContentFinder, and the method TryFindContent!

    this method will get the url of the request coming in, and you can use that to determine 'which' of your four sites in Umbraco the request belongs to, and then you can find the '404' page in that particular site, and return that as the content for the request, if you register your content finder as the LastChanceContentFinder, then a proper 404 status code will be issued too...

    There is a good example of the gist of this approach here: https://github.com/TimGeyssens/UmbracoPageNotFoundManager/blob/master/PageNotFoundManager/PageNotFoundContentFinder.cs

    In theory, the plugin does exactly what you need, but be aware of the licencing restrictions: https://github.com/TimGeyssens/UmbracoPageNotFoundManager

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft