Umbraco 17 - RedirectUrlService returning original path instead of redirection path

Hi! I’m using Umbraco cms version 17 in an headless configuration with the delivery api. To handle redirections I tried to use the RedirectUrlService in a custom delivery endpoint.

When I send a path that has a redirection, “.Url” returns the original path and not the ‘Redirected To’ value. (see screenshots).

Backoffice:

Requests:

Codebase:

Hi @andrewsouthern01

Welcome to the forum!

The .Url you’re getting back is the original route, not the destination - the redirect table just stores old URLs keyed against a content node. To get the “Redirected To” value, resolve the redirect’s content and generate its current URL via IPublishedUrlProvider. That’s exactly what Umbraco’s own ContentFinderByRedirectUrl does internally:

var redirect = await _redirectUrlService.GetMostRecentRedirectUrlAsync(path.TrimEnd('/'), culture);
if (redirect == null) return NotFound();

var content = umbracoContext.Content?.GetById(redirect.ContentId);
if (content == null) return NotFound();

var destinationUrl = content.Url(_publishedUrlProvider, redirect.Culture);

Inject IPublishedUrlProvider and IUmbracoContextAccessor (grab the context with TryGetUmbracoContext). Using the URL provider rather than the bare content.Url() extension matters in headless/load-balanced setups - it respects custom URL providers, domains, and absolute vs relative mode. Pass redirect.Culture through so variants resolve correctly. I hope that helps!

Justin

Perfect! That’s works.

Thank you!

As a sidenote, I searched through the forums before posting and it feels like Umbraco has a great community!

2 Likes

Hi @andrewsouthern01

Absolutely, it is the friendly CMS! We like to think we are one of the most welcoming and helpful tech communities out there!

Glad to have helped and hope you enjoy using Umbraco!

Justin

1 Like