Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex redirect with custom domain #268

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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