Skip to content

Commit

Permalink
Fix regex redirect with custom domain (#268)
Browse files Browse the repository at this point in the history
* Fix logic of custom domain redirect

* Imp
  • Loading branch information
luuksommers authored Jun 9, 2024
1 parent 2117b48 commit 6a23e74
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/SeoToolkit.Umbraco.Redirects.Core/Services/RedirectsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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;
});

Expand Down

0 comments on commit 6a23e74

Please sign in to comment.