Skip to content

Add an exact match option, and a redirect type per regex rule - #210

Merged
frederikvig merged 4 commits into
masterfrom
feature/exact-match-and-regex-redirect-type
Nov 7, 2026
Merged

frederikvig merged 4 commits into
masterfrom
feature/exact-match-and-regex-redirect-type

Conversation

@frederikvig

Copy link
Copy Markdown
Member

Closes #177. Closes #120.

Exact match (#177)

A redirect from /test-1 also redirected /test-1/testing, with no way to turn that off. There's now an Exact match checkbox on the Redirects tab. With it set:

  • /test-1, /test-1/ and /test-1?a=b redirect, with the query string kept.
  • /test-1/testing isn't touched by this rule, and a shorter rule can still match it.

I made it per redirect rather than a global option, as the issue only needs it on some rules. The query string of the request isn't part of the match, so links with tracking parameters still redirect. It's also in CSV and XML files, and files without it still import.

Redirect type per regex rule (#120)

Regex rules always used DefaultRedirectType. Each rule now has its own type. Rows saved earlier stay NULL, which keeps following the option, so upgrading changes nothing until someone edits a rule. Editing saves the type shown on the form.

Also fixed, from review

The regex edit form never posted the order number, so saving any edit moved the rule to the top, where it was tried first. That bug was already there, but this feature gives people a reason to edit every rule.

Check when upgrading

  • The database version goes from 2 to 3, and startup adds a column to each table, so the database user needs permission to alter them. If that fails, an error is logged and reading the redirects then fails at startup. Old instances keep working during a rolling deploy, as ExactMatch has a default and RedirectType is nullable.
  • IRegexRedirectsService has new overloads, which a class implementing it needs too. The old Update keeps the saved type. RegexRedirectFactory and the RegexRedirect constructor gained an optional parameter, so code calling them needs recompiling.
  • The CSV export has a new column.

Testing

  • Geta.NotFoundHandler.Tests 255/255 and Geta.NotFoundHandler.Optimizely.Tests 79/79. Six tests fail with the exact-match check turned off.
  • Database, on the real sandbox:
    • version 2 with existing rows upgrades to 3, and they keep ExactMatch 0 and RedirectType NULL
    • a database with none of the add-on's tables is created at version 3 with the right columns and default
    • the feature checks below pass on both
  • Over HTTP through the real forms:
    • exact match on the url, trailing slash, upper case and query string, and left alone below it and on a longer name
    • a rule without it still redirecting below
    • turning it off and on again
    • CSV and XML export and import, including a CSV without the column
    • a change made directly in the table reaching the instance through the check on the database, so it's in the checksum
    • permanent and temporary regex rules, an old NULL rule following the option on both Temporary and Permanent, and editing it
    • editing a regex rule keeping its order
    • a validation error keeping the chosen type
  • In Chrome: adding an exact redirect by clicking the real checkbox and button, and both edit dialogs showing the saved values, before the markup cleanup. After it, I checked the rendered edit form's markup over HTTP.

Not tested

  • A real rolling deploy with old and new versions side by side.
  • A database user without permission to alter tables. The behaviour described above is from reading the code.
  • Exact match on a redirect created by an automatic content move.

Known limits

  • An import or an automatic redirect for an old url that's already saved replaces the row, so it clears Exact match unless it sets it too. The wildcard setting and redirect type already work this way. Changing it means deciding how AddOrUpdate merges fields for every writer, so I left it and noted it in the changelog.
  • Sorting regex rules by Redirect Type sorts on the stored value, so NULL rows come first even though the list shows them with the default. This is cosmetic, and fixing it needs a special case in the generic sort.
  • The Update overload with a type can set a rule back to NULL, but the admin form has no way to do that. Once edited there, a rule keeps its own type.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GUDE6qHSSrhDDLNMCQ5suJ

frederikvig and others added 4 commits November 6, 2026 20:48
A redirect also applies to the urls below its old url, and there was no way
to turn that off. ExactMatch keeps it to the url itself, with or without a
trailing slash and whatever the query string. It's on the admin form and in
CSV and XML files, and files without it still import.

Regex rules always used DefaultRedirectType. Each rule can now have its own.
Rows saved earlier stay NULL, which keeps following the option, so nothing
changes for them until someone edits the rule.

Both need a column, so the database version goes to 3.

Closes #177. Closes #120.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUDE6qHSSrhDDLNMCQ5suJ
From review. The edit form never posted the order number, so saving moved the
rule to the top, and the new type gives people a reason to edit every rule.
Update without a type now keeps the saved one, the create form keeps the chosen
type through a validation error, and the query string of an exact old url has
to end on a whole parameter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUDE6qHSSrhDDLNMCQ5suJ
From /simplify. Optional parameters on IRegexRedirectsService removed the old
signatures for code already compiled against them, and made null mean opposite
things on Create and Update. Overloads keep the old ones, and null now always
means following the default. The type select on the create form uses asp-for,
which carries it through a validation error without any code, and one input
replaces the if/else around each edit checkbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUDE6qHSSrhDDLNMCQ5suJ
@frederikvig
frederikvig merged commit 1c518d0 into master Nov 7, 2026
1 check passed
@frederikvig
frederikvig deleted the feature/exact-match-and-regex-redirect-type branch November 7, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle exact matches Regex Redirect Types

1 participant