diff --git a/package/Web.config.install.xdt b/package/Web.config.install.xdt
index 3fed9e3..49c4f83 100644
--- a/package/Web.config.install.xdt
+++ b/package/Web.config.install.xdt
@@ -4,5 +4,6 @@
+
\ No newline at end of file
diff --git a/package/Web.config.uninstall.xdt b/package/Web.config.uninstall.xdt
index e94ff0a..4c6a4b3 100644
--- a/package/Web.config.uninstall.xdt
+++ b/package/Web.config.uninstall.xdt
@@ -3,5 +3,6 @@
+
\ No newline at end of file
diff --git a/source/Simple301/Core/RedirectApplicationEvents.cs b/source/Simple301/Core/RedirectApplicationEvents.cs
index 1ce4fe1..fae14ec 100644
--- a/source/Simple301/Core/RedirectApplicationEvents.cs
+++ b/source/Simple301/Core/RedirectApplicationEvents.cs
@@ -9,6 +9,7 @@
using Umbraco.Core.Persistence.Migrations;
using System;
using System.Web;
+using Simple301.Core.Utilities;
using Umbraco.Core.Services;
namespace Simple301.Core
@@ -23,7 +24,16 @@ public class MyApplication : ApplicationEventHandler
///
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
- ContentFinderResolver.Current.InsertType(0);
+ var settingsUtility = new SettingsUtility();
+
+ var customRedirectContentFinder = settingsUtility.AppSettingExists(SettingsKeys.CustomRedirectContentFinderKey) ?
+ settingsUtility.GetAppSetting(SettingsKeys.CustomRedirectContentFinderKey) :
+ false;
+
+ if (!customRedirectContentFinder)
+ {
+ ContentFinderResolver.Current.InsertType(0);
+ }
}
///
diff --git a/source/Simple301/Core/RedirectContentFinder.cs b/source/Simple301/Core/RedirectContentFinder.cs
index ba95048..ec60a63 100644
--- a/source/Simple301/Core/RedirectContentFinder.cs
+++ b/source/Simple301/Core/RedirectContentFinder.cs
@@ -1,5 +1,5 @@
using Umbraco.Web.Routing;
-using System.Linq;
+using System.Text.RegularExpressions;
namespace Simple301.Core
{
@@ -18,6 +18,22 @@ 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("(.*)"))
+ {
+ var match = Regex.Match(path, matchedRedirect.OldUrl);
+
+ if (match.Groups.Count > 1)
+ {
+ for (int iGrp = 1; iGrp < match.Groups.Count; iGrp++)
+ {
+ newUrl = newUrl.Replace($"${iGrp}", match.Groups[iGrp].Value);
+ }
+ }
+ }
+
//Found one, set the 301 redirect on the request and return
request.SetRedirectPermanent(matchedRedirect.NewUrl);
return true;
diff --git a/source/Simple301/Core/Utilities/SettingsKeys.cs b/source/Simple301/Core/Utilities/SettingsKeys.cs
index b420134..40eed50 100644
--- a/source/Simple301/Core/Utilities/SettingsKeys.cs
+++ b/source/Simple301/Core/Utilities/SettingsKeys.cs
@@ -7,5 +7,6 @@ public static class SettingsKeys
{
public static string CacheDurationKey = "Simple301.CacheDurationInSeconds";
public static string CacheEnabledKey = "Simple301.CacheEnabled";
+ public static string CustomRedirectContentFinderKey = "Simple301.CustomRedirectContentFinder";
}
}