ConfigGenerator

Cloudflare _redirects Generator

Generate Cloudflare Pages _redirects files for 301 redirects, clean URLs, domain redirects, SPA fallback, and old route migration.

Output:A ready-to-use configuration file for Cloudflare _redirects with best practices applied.

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

Rule 1

Global Options

File Location

Where to place your _redirects

Source Repository
public/_redirects
After Build
out/_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

Use a Cloudflare _redirects Generator when you need to safely redirect old URLs, manage domain redirects, or create an SPA fallback rule in your Cloudflare Pages deployment without writing the syntax manually.

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

  1. Select your framework to get accurate placement instructions.
  2. Enter the source path you want to redirect.
  3. Enter the destination URL.
  4. Select the HTTP status code (301, 302, 307, 308, or 200).
  5. 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?
The _redirects file is a plain text file you place in your build output directory to tell Cloudflare Pages how to route traffic. You can use it to redirect old URLs to new URLs (301), rewrite paths, or create an SPA fallback.
Where do I put _redirects in Cloudflare Pages?
It must end up in the root of your deployment folder. For most frameworks (Next.js, React, Astro), you place it in the public/ folder, and the build tool copies it to the final dist/ or out/ folder automatically.
How do I create a 301 redirect in Cloudflare Pages?
Add a line to your _redirects file in the format: '/old-page /new-page 301'. Cloudflare Pages will execute a permanent redirect when a user hits /old-page.
How do I redirect old routes to new routes with wildcards?
You can use splats. For example: '/blog/* /articles/:splat 301' will redirect /blog/my-post to /articles/my-post.
How do I add SPA fallback in Cloudflare Pages?
Add '/* /index.html 200' to the bottom of your _redirects file. This rewrites all unmatched requests to index.html so your client-side router (like React Router) can take over. Be careful, as this may hide real 404 errors for missing assets.

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.

Related Tools