Migration Helpdesk
Migration Helpdesk
@MigrationHelpdesk

<b>Q: My regex redirect rule is catching URLs it shouldn't — what went wrong?</b>

<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.
Этот пост опубликован в Telegram-канале Migration Helpdesk. Подписаться можно по ссылке: @MigrationHelpdesk.
tech

Свежие посты в категории «Tech Infrastructure»

Все каналы категории →

start

Готовы запустить рекламу через сеть public.tg?

Новый оффер, продукт, GEO, кейс, событие или партнёрский запуск — соберём маршрут под задачу и отдадим медиаплан.

Telegram для медиаплана: @dumay. Быстрый тест: $20 за канал, $1000 за пакет по сети.