Stop Hardcoding 301s: How I Built a Redirect Engine That Doesn't Break at 2 A.M.
Marketing wants an A/B landing page by Friday. Product wants to gracefully deprecate a legacy API without breaking old mobile clients. Growth wants ten thousand short links, and Ops does not want ten thousand Nginx edits. At some point, a single return 301 in your CDN stops being a configuration problem and becomes a routing product . Someone has to answer, on every HTTP request: Given this host, path, query, and method—where does this visitor go, and with which status code? I built that answer as a pipeline at LinkShift . Not a pile of special cases, but a fixed sequence of steps that runs the exact same way for real visitors and for the tools you use to test rules before rollout. Here is how I designed a deterministic redirect engine, the pipeline that powers it, and the edge cases that kept me up at night so they don't have to keep you up. Why "Usually Works" Is Not Enough A redirect engine fails quietly. The browser follows a broken 302 and nobody files a ticket. The damage shows up days later in analytics: wrong campaign, wrong locale, or an infinite loop that only appears when two rules on the same host point at each other. What I wanted early on was boring, bulletproof reliability: Same inputs → same decision. Two engineers simulating the same request against the same rule set should get the same target URL. Same resolution logic everywhere. Matching and destination resolution must not diverge between the "Test Rule" button in the dashboard and an actual click on a custom domain. Guards before cleverness. Rate limits and access checks run before anyone evaluates a ternary conditional in a destination string. Expressiveness is easy. Ordering is what saves you in production. The Pipeline, Told as a Story Picture a request hitting a hostname. Before the engine asks "which rule wins?", the request walks through a strict corridor of gates. Only then does it enter the rule loop. Gate 1: The Host Has to Exist If the hostname does not resolve to a domain or LinkShift