nginx to Cloudflare Redirects Converter

Moving a site to Cloudflare Pages? Paste your nginx configuration and get a ready-to-paste _redirects file with the same paths, targets and status codes. Rules that cannot be translated are reported in the notes panel, so nothing disappears quietly during the migration.

nginx configuration

_redirects file


            
            

Ready — paste some input or load the sample.

100% Client-Side · Privacy First. This tool runs entirely inside your browser. Nothing you type is uploaded, logged or sent to a server — you can even use it offline.

Overview

Nginx expresses redirects in several different ways, and each one needs a slightly different translation when the site moves to Cloudflare Pages. A plain return 301 directive maps directly onto a redirect line. A rewrite rule with a regular expression does not: Cloudflare has no regular expressions in a _redirects file, only a literal path prefix plus a wildcard that is captured as :splat. Prefix locations are the easy case, while regex locations have to be approximated with the literal part of the pattern. This converter reads an nginx configuration and produces a _redirects file, converting rewrite directives and return codes, converting capture references such as $1 into :splat, and ignoring the commented-out rules that people leave behind in production configs. It also handles the ^~ prefix modifier, which is a common source of confusion, and reports every rule it had to approximate so you can check them before deploying.

How to use the nginx to cloudflare redirects converter

  1. 1Copy the redirect rules from your nginx server or location blocks.
  2. 2Paste them into the input panel.
  3. 3Read every line that the notes panel marks as approximated, because those rely on a literal prefix instead of a regular expression.
  4. 4Test the important paths once the file is deployed.
  5. 5Upload the result as _redirects in the root of your Cloudflare Pages project.
  6. 6Keep the original nginx configuration next to the generated file, so you can diff the two whenever a route changes later.

Cheat sheet

The syntax you will use most, and what each part does.

PatternWhat it means
return 301 /new; Becomes a plain source and destination line with the status code as the third field.
rewrite ^/old/(.*)$ /new/$1 permanent; Becomes /old/* /new/:splat 301 with a comment that the pattern was approximated.
rewrite ... redirect; The redirect keyword means a 302 temporary redirect.
location ^~ /assets The prefix modifier is dropped, because Cloudflare matches a literal prefix anyway.
$1 and $2 Several capture groups collapse into the single :splat placeholder, because a Cloudflare Pages _redirects file has no :splat2. A rule that cannot be expressed that way is left out and reported.
# commented rules Comment lines are ignored, so a disabled rule stays disabled after the conversion.

Common mistakes

A redirect does not match the path you expected.

Cloudflare matches a literal prefix, so a regular expression such as ^/old/(.*)$ only works through its literal part. Review every line the converter marked as approximated.

The capture group ends up in the destination.

A dollar reference that was not converted means the rule uses a variable nginx resolves at runtime, such as a request header. Such a rule needs a Worker instead of a static redirect.

A disabled rule comes back to life.

Check that commented rules are still commented in your source. The converter drops comment lines, so an active rule in the source becomes an active rule in the output.

The status code is missing.

A redirect without an explicit code is a temporary 302. Use the permanent keyword or the 301 code when the move is permanent.

Worked examples

A regex rewrite

rewrite ^/old/(.*)$ /new/$1 permanent;

The line /old/* /new/:splat 301 with a comment marking the pattern as approximated.

A simple return directive

location /old { return 301 /new; }

The line /old /new 301 with no wildcard, because the path has no captured part.

Frequently asked questions

What cannot be migrated to a _redirects file?

Anything that is not a plain redirect. An internal rewrite, a proxy_pass, a custom error page, a rewrite map and a condition such as a RewriteCond all need a Worker or a Pages Function.

Why did the output lose the comment lines?

The generated file contains the rule lines only, so it can be copied straight into a deployment without carrying over stale commentary. Every explanation about an approximated rule is in the notes panel instead.

Can I paste a whole nginx configuration?

Yes. The parser looks for return and rewrite directives anywhere in the text and ignores everything else, so you can paste a complete server block.

Does it handle the ^~ modifier?

Yes. A prefix location becomes a wildcard match, because Cloudflare matches a path prefix with a trailing asterisk, and the notes panel records the conversion.

How are the capture groups handled?

An nginx capture such as $1 becomes :splat. A Cloudflare Pages _redirects file only supports that one placeholder, so a rule with several capture groups is left out of the file and reported with the Cloudflare Bulk Redirect or Worker alternative.

What happens to a rule that is commented out?

It is ignored. A hash starts a comment in nginx as well, so a disabled rule never comes back to life in the generated file.

Which status codes are used?

The code from the return or rewrite directive is kept. A rewrite with permanent becomes 301 and a rewrite with redirect becomes 302, which are the closest Cloudflare equivalents.

Can I merge the result with an existing _redirects file?

Yes. The rules are plain lines, so paste them below the ones you already have. Remember that Cloudflare evaluates the first matching rule, so the order still matters.

Can I convert an internal rewrite?

No, not into a redirect file. An internal rewrite serves different content under the same URL, which a _redirects file cannot express, so it needs a Worker or a Pages Function.

What happens to a return directive with a body?

Only the status code and the target are used. The response body that nginx would send is dropped, because a redirect file only sets the status and the location.

Does it handle a rule that redirects to an external domain?

Yes, the external target is copied through unchanged and the notes point out that it is an external URL, so you can review it before you deploy.