Engineering · · 3 min read
Cloudflare Quietly Dropped a Third of My Redirect Rules
Moving this site from WordPress to Cloudflare Pages, I wrote 651 redirect rules. The deploy succeeded with no warnings — and every rule from line 430 on did nothing. Separately, the new wrangler nearly converted the whole project to a different deployment model.
This site used to be WordPress, with old URLs at the root, like /secrets-of-japanese-convenience-stores/. After moving to a static site on Cloudflare Pages, those URLs had to 301 to their new homes, or search engines and external links would all hit 404s.
651 rules, deploy succeeded
The old site had 309 posts and 10 pages, plus category, tag and feed paths. A script generated Cloudflare's _redirects file: hand-picked posts to their new URLs, the rest to the notes index. WordPress served URLs with or without the trailing slash, so each rule also got a slash-less twin. 651 rules in total — far below the 2,000 static rules the documentation allows.
The deploy went smoothly. The output said Uploading _redirects and nothing else. No warnings.
Only checking every URL showed it
I had written a separate check: request every old URL on the new site, assert a 301, then request the target and assert a 200.
All 322 old URLs with trailing slashes passed. The single failure was a slash-less URL I'd thrown in as a spot check: 404. Its rule was right there in the file.
So I sampled by line number: the rule on line 340 worked, line 400 worked, line 500 didn't, line 600 didn't. A binary search between 400 and 500 pinned it down: line 429 works, everything from line 430 on is dead. Line 430 starts about 25.7 KB into the file.
Nothing about the rules themselves differs. The only explanation is that Cloudflare read roughly the first 25 KB of the file and silently ignored the rest. Over two hundred of the 651 rules had never worked.
The fix
- WordPress's canonical URLs all end in a slash, and nearly every link out in the wild has it. So slash-less twins now exist only for the 14 hand-picked posts and a few pages. The file went from 39 KB to 21 KB.
- The generator now has a gate: above 24 KB it exits with an error, so silent truncation can't happen again.
- The check script became a fixed step after every deploy. After redeploying, all 323 old URLs redirect to 19 targets, every target returns 200, and the last rule in the file is confirmed to work.
A side trap: wrangler deciding for me
The same day brought another trap. The new wrangler (4.169), run as wrangler pages project create in a project without a config file, first does "autoconfig detection": it saw Next.js, installed the OpenNext adapter, rewrote the scripts in package.json and next.config.ts, generated a wrangler.jsonc, and created an R2 bucket in my Cloudflare account. All I wanted was a plain static site.
I reverted each change, confirmed the bucket was empty and deleted it, then added a wrangler.toml stating pages_build_output_dir = "out". With a config file present, autoconfig doesn't run.
Rules I wrote down
- The documented limit isn't necessarily the only limit. You can be under the rule count and over a file-size cap.
- "Deploy succeeded" only means the upload succeeded. Verify redirects, headers and similar config live, one by one.
- Whatever can be caught at generation time should fail at generation time. Don't count on the platform to warn you.
- After a tool upgrade, check whether it will change your project on its own; pin the behaviour with an explicit config file.