If you’ve ever stared at a spreadsheet full of old URLs and wondered how to turn it into a clean
Nginx redirect file, welcome. Tonight’s ritual: turn chaos into a tidy redirects.conf
that ships without redirect loops, broken campaigns, or SEO faceplants.
The goal is simple: move the site, keep traffic, and avoid “why is everything 404?” Slack pings. We’ll use TinyUtils Sitemap Delta because it makes the boring parts fast: pairing old URLs with new ones and exporting rules you can actually review.
TL;DR
- Collect your old URLs (sitemap + analytics + logs).
- Collect your new URLs (new sitemap or staging crawl).
- Normalize both lists (slashes, casing, host, params).
- Pair old → new in Sitemap Delta.
- Export Nginx rules, run
nginx -t, spot-check, then deploy.
Inputs (the ingredients)
Redirects go wrong when the inputs are sloppy. Spend ten minutes here and you buy yourself a calm launch. Here’s the minimal kit:
- Old URL list: your current sitemap is best. Add top landing pages from analytics and any weird “high traffic but missing from sitemap” pages.
- New URL list: the new sitemap is ideal. If the new sitemap isn’t ready, crawl staging or export from your CMS.
- A clear policy: canonical host, HTTPS, casing, trailing slash rules. Write these down. Humans need a north star when the list hits 1,000 rows.
- A text editor + git: treat redirects like code. Commit the file. Review it like code. Roll it back like code.
- One tool tab: keep Sitemap Delta open while you pair.
Mapping: old → new (with a real-world mindset)
Picture a site that’s been online since 2012. Posts moved folders. Product pages got renamed. The new CMS enforces lowercase and trailing slashes. Analytics says 600 old URLs still get traffic. Great.
The mapping job has one rule: send people to the closest relevant page. Dumping everything on the homepage is lazy, it kills conversion tracking, and it makes the site feel broken even when it “technically redirects.”
In Sitemap Delta, paste your old list on one side and the new list on the other. The diff table will surface obvious matches, orphans, and “this looks close but check it” candidates. Take the time to approve matches deliberately.
Normalization checklist (do this before pairing)
- Lowercase paths (Nginx paths are case-sensitive).
- Pick a slash policy (
/pagevs/page/) and normalize. - Strip protocol and host when building path-based rules.
- Decide what happens to query params (keep, drop, or selectively keep).
- Remove obvious tracking noise (
utm_*,fbclid, etc.) from the mapping sheet.
Generate the Nginx rules (the ceremony)
Once you have pairs, exporting rules is the easy part. The hard part is keeping the rules readable and safe. Use anchors. Keep wildcards scoped. Comment your intent.
- Export “Nginx 301” from Sitemap Delta. You’ll get properly escaped rules plus a safety header.
-
Save as
redirects.confin git. Put it near your deployment scripts so it’s obvious where it lives. - Prefer explicit rules for high-traffic pages. Regex is powerful. Regex is also how you summon bugs.
Example redirect file (annotated)
# redirects.conf — generated with TinyUtils Sitemap Delta
# Policy: force HTTPS + canonical host, keep trailing slash, avoid greedy wildcards
rewrite ^/Blog/Case-Study-2019/?$ https://example.com/blog/case-study-2019/ permanent;
rewrite ^/press/launch$ https://example.com/news/product-launch/ permanent;
rewrite ^/docs/(.*)$ https://example.com/help/$1 permanent;
rewrite ^/category/widgets/(.*)$ https://example.com/products/widgets/$1 permanent;
# Legacy tag page folded into hub
rewrite ^/tag/seo-tips/?$ https://example.com/learn/seo/ permanent;
# Catch-all for ancient PHP endpoints
rewrite ^/index\.php$ https://example.com/ permanent;
Keep the file boring. Boring is stable. If you must use broad regex, test it against real inputs and watch for overlap.
Testing (how to avoid redirect demons)
-
Dry run locally: include the file and run
nginx -t. Fix syntax issues before anyone else finds them. -
Spot-check 20 URLs:
curl -I -L https://example.com/old. Verify 301 and the final destination. - Bulk sanity: run a crawl after deploy and look for 404s shrinking and redirect chains staying short. Dead Link Finder is great for a quick pass.
Validation checklist
- ✅
nginx -tpasses with the file included - ✅ Top URLs redirect to the intended destination with a single hop
- ✅ Search Console 404s trend down after deploy
- ✅ Redirect rules live in git with a short README
FAQ (quick answers you’ll be asked anyway)
Do I need regex for pagination? Usually you can avoid it. If your old site had
/page/2/ style URLs, a scoped rule like ^/page/(\d+)/?$ is fine. Keep it
anchored. Keep it specific. Test it with real inputs.
How big can the file be? Thousands of rules are fine. What hurts is a file nobody can read. Group by section (blog, docs, products), add comments, and keep a short changelog at the top.
301 vs 302? Use 301 for permanent moves. Use 302 for temporary campaigns and write down the expiry date so it doesn’t live forever.
Common mistakes (and how to dodge them)
- Slash drift: mixing
/pageand/page/creates loops. Pick one and normalize inputs. - Host drift: always redirect to your canonical host with HTTPS.
- Case sensitivity: lowercase inputs early or you’ll miss matches.
- Regex overreach: a single
(.*)can swallow sections you didn’t mean to touch. - Query strings: decide deliberately; test
?ref=variants if they matter.
Next steps
If you’re doing a full migration, pair this with a broken-link scan before and after launch. Redirects and 404 cleanup are a loop: map → ship → scan → patch. A small daily pass for a week beats a single panicked night later.
Mini playbook for teams
Redirects are one of those “everyone has an opinion” areas, so roles help. Keep it simple:
- SEO lead: owns the mapping, defines canonical rules, signs off on orphans.
- Engineer: reviews syntax, runs
nginx -t, deploys via CI. - Content lead: verifies top landing pages land on the right refreshed content.
- QA: runs the spot-check list and keeps a short evidence note.
Performance and safety tips
- Order matters: specific rules first, wildcards last. Nginx stops at the first match.
- Group logically: future reviews are faster when related rules sit together.
- Monitor after launch: watch for 500s and long redirect chains. Fix the ugly ones early.
- CDN hygiene: if you’re behind a CDN, purge after deploy so caches learn the new routes.
Ready to generate the file? Open Sitemap Delta, paste your lists, confirm the pairs, and export Nginx rules.
Generate redirects now
Compare sitemaps and export nginx/Apache rewrite rules automatically
Generate Redirects →