Copied to clipboard

Flag this post as spam?

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


  • Gavin Williams 22 posts 132 karma points
    Jan 15, 2021 @ 15:33
    Gavin Williams
    0

    Intercepting the 404 to perform redirect logic

    I'm after some advice. I'm in the process of rewriting our existing v6 website for v8 which will be a new site, but the original will still be available for now. The content is being re-entered manually as its also a good opportunity to clean out old content.

    Each new page has a legacy id property so the editor can key in the page id from the old site as they move it over. I've created a custom lookup table keyed on old id that stores the page url from the old site.

    What I'd like to do is intercept the 404 page from visitors who have bookmarked the old url, check whether it exists in my lookup table and if so redirect to the new page that contains the legacy id property.

    How can I intercept the 404 to do the above check? For performance reasons I don't want to intercept every request unless I have to, I'd just like some code to run when umbraco is returning the 404.

  • Nik 1391 posts 6128 karma points MVP 3x c-trib
    Jan 15, 2021 @ 16:16
    Nik
    100

    Hi Gavin,

    I would recommend creating a content finder. You can then inject this into the content finder collection before the last chance content finder.

    This would then let Umbraco try and find the page and return it if found, else it hits your code to try and find it, and if that then fails it will feed back into the default 404 pipeline :-)

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

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft