Cookie Settings

Choose which cookies to allow.

Full list in our Privacy Policy.

Cloudflare Redirect Rules Not Working: How to Find the Cause and Fix It

A curl test splitting into a request that stops before the redirect rule and a redirect loop, the two ways Cloudflare redirect rules stop working

Cloudflare redirect rules not working means one of two things: the rule never sees the request, or it fires and another redirect sends the visitor back until the browser stops with ERR_TOO_MANY_REDIRECTS. The causes are few: a DNS record Cloudflare doesn’t proxy, a pattern that doesn’t match the full URL, another rule that answers first, a redirect cached in your browser, or an SSL/TLS encryption mode that loops with your server. One curl command tells you which one you have. Lelops Advise reads your zone’s DNS records and SSL/TLS encryption mode, checks them against Cloudflare’s documentation, and makes the fix when you ask.

Cloudflare Redirect Rules Not Working? Find the Cause With curl

Run curl -sI on the exact URL that should redirect, with its scheme and query string, for example curl -sI "http://www.example.com/old-page?ref=mail". curl keeps no cache, and its answer points to the cause:

  • No cf-ray header: Cloudflare’s Cf-Ray header names the data center that processed the request, so without it the request never went through Cloudflare. Check the DNS record.
  • A cf-ray and a 200: no redirect rule matched the request. Check the pattern.
  • A 301 or 302 to the wrong place: another rule matched first, or the target drops part of the URL.
  • Two URLs alternating with curl -sIL: a loop. Check the encryption mode.

Rules simulator then lists the rules that apply to a request, in order.

Why a Redirect Rule Never Fires, and How to Fix It

A request leaving its path before it reaches the Cloudflare redirect rule: a cached 301, a DNS-only record, another rule that answers first

  1. Proxy the DNS record. Single Redirects and Bulk Redirects require proxied DNS records: a DNS-only record (the grey cloud) makes Cloudflare answer with your server’s IP and stay out of the HTTP traffic. www.example.com and example.com are two records. A domain with no server needs a proxied record pointing to 192.0.2.0 or 100::, Cloudflare’s originless setup.
  2. Match the whole URL. A Wildcard pattern must match the entire URL, scheme and query string included. Write http*://example.com/*, as Cloudflare’s domain redirect example does, not https://example.com/*. Give the apex its own pattern, since *.example.com matches subdomains only, and end a page’s pattern with * so ?utm_source=mail doesn’t stop the match.
  3. Keep the query string and path. Turn on Preserve query string, off by default, and put ${1}, ${2} in the target for what each * captured, as in https://example.net/${2} for http*://example.com/*.
  4. Find the rule that answers first. Cloudflare runs Single Redirects before Bulk Redirects and uses the first rule that matches, like WAF custom rules, so narrow a broad rule earlier in the list. A redirect rule also wins over a Forwarding URL Page Rule: turn the old Page Rule off once your rule covers its URLs, and check the audit log for rules you don’t recognize.
  5. Test with a 302. Rules return a 301 by default, and HTTP’s standard makes 301 and 308 responses cacheable, so your browser can replay an old target. Use 302 until the target is right.

How to Fix a Cloudflare Redirect Loop

Cloudflare in Flexible mode and the origin sending a visitor back and forth, fixed by setting the encryption mode to Full (strict)

A loop means two redirects send the visitor back and forth, and the pair to check first is the SSL/TLS encryption mode and your origin’s own HTTPS redirect. In Flexible mode, Cloudflare reaches your origin over plain HTTP, so an origin that redirects HTTP to HTTPS sends the visitor back to https:// and the loop restarts. In the 86 broken redirects we read on Stack Overflow and its sister sites, 28 came from this setting, more than any other Cloudflare cause.

  1. Set the mode to Full (strict). It needs a certificate on the origin, and as our Cloudflare configuration guide explains, Flexible leaves the leg between Cloudflare and your server unencrypted.
  2. Check Always Use HTTPS. It redirects every HTTP request to HTTPS, so it loops with an origin that redirects HTTPS to HTTP.
  3. Exclude Cloudflare’s own paths. Leave /cdn-cgi/challenge-platform/ out of the rule to avoid challenge loops, and /.well-known/ for certificate validation.

How to Fix Cloudflare Redirect Rules Not Working with Lelops Advise

Ask Lelops checking a zone’s DNS record and SSL/TLS encryption mode and setting them to Proxied and Full (strict)

Lelops Advise is the AI assistant in Lelops for teams running Cloudflare: Ask Lelops answers from your live configuration and Cloudflare’s documentation, and makes the change when you ask.

  1. Open Ask Lelops, the chat panel on the right side of the Lelops app, and name the zone and the URL that fails, for example http://www.example.com/old-page.
  2. Paste your curl -sI output and ask which case it shows: a request that missed the rule, or a loop. Ask Lelops answers from Cloudflare’s documentation and cites the pages its answer relies on.
  3. No cf-ray: check the DNS record. Ask whether the record for www.example.com is proxied. Ask Lelops lists the zone’s DNS records with their proxy status. If the record is DNS-only, ask it to turn the proxy on; for a domain with no server, ask it to create a proxied record pointing to 192.0.2.0. Both need the API token you connected to allow DNS edits.
  4. A loop: check the encryption mode. Ask for the SSL/TLS encryption mode and the Always Use HTTPS setting of example.com. If the mode is Flexible and your server redirects to HTTPS, ask Ask Lelops to set Full (strict) once the origin has a certificate. If your server redirects HTTPS to HTTP instead, ask it to turn Always Use HTTPS off. Both need the token to allow zone settings edits.
  5. A 200 or the wrong target: check the pattern. Paste the rule’s Request URL, target URL and Preserve query string setting, with the URL you tested. Ask Lelops reads your DNS records and zone settings, not your redirect rules, so it works from what you paste and checks it against Cloudflare’s wildcard documentation.
  6. Confirm with curl. Run curl -sI again on the same URL, and curl -sIL after a loop fix.
  7. Roll back if another page breaks. Each change Ask Lelops makes to DNS records and zone settings is saved in a version. An Administrator can restore the version from before the change with Restore and deploy, which brings back every tracked setting of the zone as it was in that version.

When a redirect breaks, Lelops Advise checks your DNS records and SSL/TLS mode against Cloudflare’s documentation and makes the fix you ask for: lelops.ai/product/advise.

FAQ

Why is my Cloudflare redirect rule not working?

A Cloudflare redirect rule fails in one of two ways: the request never reaches the rule, or the rule fires and another redirect sends the visitor back in a loop. The first case comes from a DNS record that isn't proxied, another rule that matches first, a cached redirect in the browser, or a pattern that doesn't match the full URL. The second comes from the SSL/TLS encryption mode or from two redirects that undo each other. A curl request on the exact URL shows which of the two cases applies.

Do Cloudflare redirect rules work on DNS-only records?

No. Cloudflare's documentation states that Single Redirects and Bulk Redirects require proxied DNS records, because a DNS-only record sends visitors straight to the server and Cloudflare never handles the HTTP request. A domain that exists only to redirect can use a proxied placeholder record pointing to 192.0.2.0 or 100::, which Cloudflare documents for setups without a server.

Why does my Cloudflare redirect cause too many redirects?

Too many redirects means two redirects send the visitor back and forth. The most frequent pair is the Flexible SSL/TLS encryption mode, where Cloudflare reaches the server over HTTP, and a server that redirects HTTP to HTTPS. Switching the zone to Full or Full (strict), with a certificate on the server, ends that loop. Other loops come from Always Use HTTPS facing a server that redirects to HTTP, or from two rules pointing at each other.

Which runs first, Cloudflare redirect rules or Page Rules?

Redirect rules (Single Redirects) run first, and when a redirect rule and a Page Rule both match a request, the redirect rule wins. Bulk Redirects also run after Single Redirects. A partly migrated zone can therefore behave two ways: URLs the new rule matches follow the new rule, and the others still follow the old Page Rule.

How do I test a Cloudflare redirect without the browser cache?

Engineers test redirects with curl, which keeps no cache: curl -sI on the URL returns the status code and the location header as Cloudflare sends them at that moment, and curl -sIL follows each hop to reveal a loop. Browsers can keep a 301 or 308 redirect and replay it without contacting Cloudflare, so a browser test can show a redirect that no longer exists. Setting the rule to a 302 while testing avoids that.

Get started

Connect Cloudflare. See where your edge stands today.

Your first configuration health report, with the fixes to make first, in minutes.

  • No credit card required