<b>Q: My regex redirect rule is catching URLs it shouldn't — what went wrong?</b>
This bites almost everyone who writes pattern-based redirects. You're not bad at this.
Short answer: your pattern is probably unanchored or greedy, so it matches more than you meant.
Long answer: a rule like <code>/blog/(.*)</code> with no end anchor will happily grab <code>/blog-archive/x</code> too if your engine matches loosely. And <code>.*</code> is greedy — it'll swallow query strings and trailing slashes you wanted to keep. Worse, rules are evaluated top-down, so a broad pattern near the top eats traffic meant for a specific rule below it.
Three fixes that solve most cases:
— anchor both ends: <code>^/blog/(.*)$</code>
— put specific rules above broad ones
— test against a list of 20 real URLs, including edge cases
Next step: pull 20 sample old URLs, run them through your rules in order, and confirm each lands where you intended before deploy.
Migration Helpdesk
@MigrationHelpdesk
<b>Q: My regex redirect rule is catching URLs it shouldn't — what went wrong?</b>
Этот пост опубликован в Telegram-канале Migration Helpdesk. Подписаться можно по ссылке: @MigrationHelpdesk.