Skip to content
This repository was archived by the owner on Apr 14, 2019. It is now read-only.
Open
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
27 changes: 24 additions & 3 deletions source/Simple301/Core/RedirectContentFinder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Umbraco.Web.Routing;
using System.Linq;
using System;
using System.Text.RegularExpressions;
using Umbraco.Web.Routing;

namespace Simple301.Core
{
Expand All @@ -18,8 +19,28 @@ public bool TryFindContent(PublishedContentRequest request)
var matchedRedirect = RedirectRepository.FindRedirect(path);
if (matchedRedirect == null) return false;

// Groups match replace
string newUrl = matchedRedirect.NewUrl;

if (matchedRedirect.IsRegex && matchedRedirect.OldUrl.Contains("(.*)"))
{
try
{
var match = Regex.Match(path, matchedRedirect.OldUrl);

for (int iGrp = 1; iGrp < match.Groups.Count; iGrp++)
{
newUrl = newUrl.Replace($"${iGrp}", match.Groups[iGrp].Value);
}
}
catch (Exception)
{
return false;
}
}

//Found one, set the 301 redirect on the request and return
request.SetRedirectPermanent(matchedRedirect.NewUrl);
request.SetRedirectPermanent(newUrl);
return true;
}
}
Expand Down