skybrud / Skybrud.Umbraco.Redirects

Redirects manager for Umbraco.
https://packages.limbo.works/skybrud.umbraco.redirects/
MIT License
38 stars 41 forks source link

Site specific redirect only works for unique domains #191

Open bjarnef opened 10 months ago

bjarnef commented 10 months ago

Which version of Skybrud Redirects are you using? (Please write the exact version, example: 4.0.8)

4.0.17

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

12.2.0

Bug description

We have a multi-site project with the following sites

Site A (English) domain.com Site B (Danish) domain.com/da Site C (Norwegian) domain.com/no Site D (Swedish) domain.com/se etc.

If we added a site specific redirect for e.g. Norwegian site e.g. /no/test?hello=world this didn't have any effect, but if moved to main site /test?hello=world it did work.

I suspect it does work with unique domains e.g. if Norwegian site has domain domain.no or no.domain.com and it is an issue because it probably match first site with domain (but the site id doesn't match), so no match was found and redirect didn't have any effect.

While on Site A it find the match because it is first domain with site/root id found, which match the site id on the redirect.

Not sure if the order of the sites matter or it depends on the order the domains was created in Umbraco.

abjerner commented 10 months ago

Hi @bjarnef

Can you run this partial Razor view somewhere in the solution? And if so, what does it return?

@using Umbraco.Cms.Core.Services
@using Skybrud.Umbraco.Redirects.Services
@using Umbraco.Cms.Core.Routing
@using Skybrud.Umbraco.Redirects.Models
@inject IDomainService DomainsService
@inject IRedirectsService RedirectsService

@{

    Uri uri = new Uri("https://domain.com/no/test");

    if (DomainUtils.TryGetDomain(DomainsService, uri, out Domain? domain)) {
        <pre>Yay -> @domain.Name</pre>
    } else {
        <pre>Bah</pre>
    }

    <hr />

    IRedirect? redirect = RedirectsService.GetRedirectByUri(uri);

    if (redirect is null) {
        <em>Not found...</em>
        return;
    }

    <pre>@redirect.Id -> @redirect.Key -> @redirect.Destination.Url</pre>

}

This should roughly align with the logic in the middleware. When I test this locally, it does find both the domain and my test redirect.

My domain configuration looks like this:

image