Cloudflare _redirects Generator
Generate Cloudflare Pages _redirects files for 301 redirects, clean URLs, domain redirects, SPA fallback, and old route migration.
Note: The _redirects file is exclusively used by Cloudflare Pages. It does not apply to Cloudflare Workers or standard proxy domains. For non-Pages domains, you must use Cloudflare Page Rules or Redirect Rules.
Redirect Rules
Global Options
File Location
Where to place your _redirects
public/_redirectsout/_redirects- •Next.js server-side redirects in next.config.ts do not work for static export on Cloudflare Pages.
- •Use output: 'export' in your Next.js config.
- •Place _redirects in the public directory before building.
- •Cloudflare Pages should deploy the 'out' directory.
/old-page /new-page 301
Quick Summary
What is this tool?
The Cloudflare _redirects file is a simple, powerful tool for managing routing directly at the edge. It takes precedence over your framework's routing logic in static deployments.
Each line in the file represents a single rule, defining a source URL, a destination URL, and an HTTP status code (like 301 for permanent, 302 for temporary, or 200 for a rewrite).
How to Use This Tool
- Select your framework to get accurate placement instructions.
- Enter the source path you want to redirect.
- Enter the destination URL.
- Select the HTTP status code (301, 302, 307, 308, or 200).
- Add the rule and copy the resulting file.
What This Tool Generates
_redirects— A plain text file containing your routing rules.
Best Practices
- Always put your most specific redirect rules at the top of the file, and catch-all rules (like SPA fallbacks) at the very bottom.
- Use 301 for permanent SEO migrations and 302/307 for temporary redirects.
- If you need to force a redirect even if a static file exists at the source path, you can append an exclamation mark to the status code (e.g., 301!).
Common Mistakes
- Putting an SPA fallback ('/* /index.html 200') at the top of the file, which overrides all other rules.
- Using Next.js next.config.ts redirects for static exports. Next.js server config is ignored when using 'output: export' on Cloudflare Pages; you must use _redirects instead.
- Using an invalid status code. Cloudflare Pages only supports 301, 302, 303, 307, 308 for redirects, and 200 for rewrites.
Security Notes
- When redirecting to external domains, ensure you trust the destination to prevent open redirect vulnerabilities.
- Be careful using rewrites (200) to external URLs, as this makes your domain act as a proxy and could expose you to security or billing risks.
Frequently Asked Questions
What is a Cloudflare _redirects file?
Where do I put _redirects in Cloudflare Pages?
How do I create a 301 redirect in Cloudflare Pages?
How do I redirect old routes to new routes with wildcards?
How do I add SPA fallback in Cloudflare Pages?
How We Keep Your Configs Safe & Valid
Built-in Error Checking
Every file is checked against official rules. We catch missing fields and bad syntax. YAML indentation errors are flagged right away. Kubernetes, Terraform, and Docker specs are all covered. API versions and labels are verified too. You get valid output every time you generate.
100% Private & Local
All tools run in your browser only. Your API keys never leave your machine. We do not use any tracking scripts. No data is sent to any server. Passwords and secrets stay on your device. Crypto operations use the Web Crypto API. Your privacy is fully protected at all times.
Secure Settings by Default
Configs use safe defaults out of the box. Containers run as non-root users. Root filesystems are set to read-only. Dangerous Linux capabilities are dropped. Network policies limit pod-to-pod traffic. TLS 1.3 is enabled for web servers. Security headers are added where needed.
Ready for CI/CD & Git
Output files are ready for your Git repo. Use them with ArgoCD, Flux, or GitHub Actions. Files use clear formatting and comments. Code review is easy for your team. Indentation and key order are consistent. Test in staging before going to production. Every file is clean and well-structured.
Infrastructure as Code
Store configs in Git alongside your code. Terraform modules include typed variables. Backend configs support remote state locking. Outputs work across multiple modules. Ansible playbooks use clear task steps. Chef and Puppet configs are also supported. Every file works with version control tools.
Monitoring & Tracing
Set up Prometheus with auto-discovery rules. Create Grafana dashboards with template variables. Add alerting rules with severity labels. Use OpenTelemetry for trace collection. Forward logs to Loki or Elasticsearch. Connect to Jaeger or Tempo for tracing. Monitor metrics, logs, and traces together.
Container & Docker Safety
Dockerfiles use multi-stage builds for small images. Base images are pinned to exact versions. Dev files are excluded from final images. Health checks are added for orchestrator use. Containers switch to non-root users. Docker Compose uses named volumes and networks. Resource limits are set in deploy configs.
Multiple Output Formats
Export as YAML, JSON, HCL, or TOML. Kubernetes uses YAML with proper separators. Terraform uses HCL with correct escaping. JSON output has consistent indentation. Copy to clipboard with one click. Preview output with syntax highlighting. Line numbers help you review quickly.