From 6a23e745c02d38eab64f12ac1f008c44b8df1246 Mon Sep 17 00:00:00 2001 From: Luuk Sommers Date: Sun, 9 Jun 2024 19:40:03 +0200 Subject: [PATCH] Fix regex redirect with custom domain (#268) * Fix logic of custom domain redirect * Imp --- .../Services/RedirectsService.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/SeoToolkit.Umbraco.Redirects.Core/Services/RedirectsService.cs b/src/SeoToolkit.Umbraco.Redirects.Core/Services/RedirectsService.cs index 076f72d..1daf3b8 100644 --- a/src/SeoToolkit.Umbraco.Redirects.Core/Services/RedirectsService.cs +++ b/src/SeoToolkit.Umbraco.Redirects.Core/Services/RedirectsService.cs @@ -139,7 +139,7 @@ public RedirectFindResult GetByUrl(Uri uri) //Else check if we can find a redirect on the custom domain foundRedirect = redirects.FirstOrDefault(it => it.CustomDomain != null && (it.CustomDomain.Equals(customDomainWithoutScheme, StringComparison.InvariantCultureIgnoreCase) || it.CustomDomain.Equals(customDomainWithScheme))); if (foundRedirect != null) return new RedirectFindResult(uri, foundRedirect); - } + } //Else check if we can find a redirect on the global level foundRedirect = redirects.FirstOrDefault(it => @@ -151,13 +151,18 @@ it.Domain is null && var regexRedirects = _redirectsRepository.GetAllRegexRedirects().Where(it => { - if (it.Domain == null) return true; - if (domain != null && it.Domain.Id == domain.Id) return true; - if (domain is null && - !string.IsNullOrWhiteSpace(it.CustomDomain) && + // Any site + if (it.Domain == null && string.IsNullOrWhiteSpace(it.CustomDomain)) return true; + + // Find by domain + if (it.Domain != null && domain != null && it.Domain.Id == domain.Id) return true; + + // Find by Custom domain + if (!string.IsNullOrWhiteSpace(it.CustomDomain) && (it.CustomDomain.Equals(customDomainWithoutScheme, StringComparison.InvariantCultureIgnoreCase) || it.CustomDomain.Equals(customDomainWithScheme))) return true; + return false; });