Intercepting Umbraco routing

Hi

On my site I have 50-60 or more nodes/pages nested under a single parent node on multiple sites.

Is there a way I can hijack Umbraco routing so if I wanted to redirect ALL pages/nodes to another URL I could do this? Even if the user went to a child page it would automatically redirect them?

You can think of this as multiple sub sites, and I have to redirect them all (including their inner pages) to another URL/umbraco parent site.

Thanks in advance

You can use the RoutingRequestNotification for this.

Here’s a quick example that I whipped up, this is based on content type alias but you could use any logic you want here - including looking for the presence of something like a “redirectUrl” property value on the node or its parent.

public class RedirectingRequestHandler : INotificationHandler<RoutingRequestNotification>
{
    const string RedirectThisContentTypeAlias = "yourAlias";

    public void Handle(RoutingRequestNotification notification)
    {
        var content = notification.RequestBuilder.PublishedContent;

        // if content is this content type or a child of this content type
        if (content?.ContentType.Alias == RedirectThisContentTypeAlias
            || content?.Parent()?.ContentType.Alias == RedirectThisContentTypeAlias)
        {
            notification.RequestBuilder.SetRedirect("https://some-other-url");
        }
    }
}