Master Netlify Redirects and Rewrites
Intermediatev1.0.0
Configure Netlify redirects and rewrites for SPA routing, URL migrations, proxy rules, and geo-based routing using netlify.toml and _redirects file.
Content
Overview
Netlify's redirect engine handles URL routing at the CDN edge — SPA fallbacks, URL migrations, API proxying, and geo-based routing. Rules are processed in order, with the first match winning.
Why This Matters
- -SPA routing — prevents 404s on client-side routes
- -SEO migrations — preserve search rankings when URLs change
- -API proxying — avoid CORS issues by proxying through your domain
- -Geo routing — serve different content based on visitor location
How It Works
Step 1: SPA Fallback (Most Common)
Step 2: URL Migrations with 301 Redirects
Step 3: API Proxy (Avoid CORS)
Step 4: Geo-Based Routing
Step 5: Role-Based Access (with Netlify Identity)
Best Practices
- -Place specific redirects BEFORE catch-all rules (first match wins)
- -Use 301 for permanent moves (SEO credit transfers), 302 for temporary
- -Use
force = truefor proxy rules to always apply (even if file exists) - -Test redirects with Netlify's playground: netlify.com/docs/redirects
- -Use
:splatfor wildcard captures,:paramfor named captures - -Keep redirect count reasonable (< 1000 rules)
Common Mistakes
- -Placing SPA catch-all before specific redirects (overrides everything)
- -Using 302 instead of 301 for permanent URL migrations (loses SEO value)
- -Not using
force = trueon proxy rules (fails if matching static file exists) - -Mixing _redirects file with netlify.toml rules (unpredictable ordering)
- -Redirect loops (A -> B -> A)
FAQ
Discussion
Loading comments...