Repository navigation
Add an exact match option, and a redirect type per regex rule - #210
Merged
Merged
Conversation
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GUDE6qHSSrhDDLNMCQ5suJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #177. Closes #120.
Exact match (#177)
A redirect from
/test-1also 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=bredirect, with the query string kept./test-1/testingisn'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 stayNULL, 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
ExactMatchhas a default andRedirectTypeis nullable.IRegexRedirectsServicehas new overloads, which a class implementing it needs too. The oldUpdatekeeps the saved type.RegexRedirectFactoryand theRegexRedirectconstructor gained an optional parameter, so code calling them needs recompiling.Testing
Geta.NotFoundHandler.Tests255/255 andGeta.NotFoundHandler.Optimizely.Tests79/79. Six tests fail with the exact-match check turned off.ExactMatch0 andRedirectTypeNULLNULLrule following the option on bothTemporaryandPermanent, and editing itNot tested
Known limits
AddOrUpdatemerges fields for every writer, so I left it and noted it in the changelog.NULLrows 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.Updateoverload with a type can set a rule back toNULL, 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