Cloudflare Redirects: Fixing Rules, Proxy and SSL Settings
Cloudflare can answer a request with a redirect before it ever reaches your server, which makes it a good place for site-wide rules and a confusing one when something goes wrong.
Over the years Cloudflare has offered several ways to redirect, and older accounts often have rules spread across more than one of them, plus settings that redirect without looking like redirect rules. This guide shows how to confirm Cloudflare is the layer answering, list every rule that could redirect, decide which feature should own each job, and fix the proxy and encryption settings behind most Cloudflare redirect problems.
Is it Cloudflare or your server?
Before changing anything, find out which layer is producing the redirect. A response that passes through
Cloudflare carries a cf-ray header and usually server: cloudflare, but both
appear whether the redirect came from Cloudflare or from your server behind it. The clues that it was
Cloudflare itself:
- The redirect response has no headers your application normally sets, such as its own cookies or
x-powered-by. - The redirect still happens when your server is stopped or when you request a path your server does not have.
- Your server's access log has no line for the request at the time you made it.
curl -sI http://example.co.uk/old-offer | grep -iE "^HTTP|^location|^server|^cf-ray|^x-"
The Redirect Checker records the status code and Location of every hop, which lets you
see whether an edge redirect is followed by a second one from your server. That pattern, one hop from
Cloudflare and another from the origin, is the most common chain on Cloudflare sites.
The places a Cloudflare redirect can come from
Names and menus change as Cloudflare updates its products, so treat this as a map of what to look for rather than an exact menu path. At the time of writing, a zone can redirect from any of these:
| Source | What it is good for | What to watch for |
|---|---|---|
| Single redirect rules (shown as Redirect Rules) | Pattern-based and site-wide rules: host changes, folder moves, HTTPS, conditions on country or device | Rules run in the order listed, and a match may stop later redirect rules running |
| Bulk redirects | Long lists of old URL to new URL, such as migrations | Lists live at account level and must be switched on by a separate bulk redirect rule |
| Page Rules (legacy) | Older forwarding URL rules on long-standing accounts | Cloudflare has been moving users away from them; old rules may still be active and forgotten |
| "Always Use HTTPS" setting | Upgrading every http request | Redirects without appearing in any rules list |
| Workers and similar code features | Logic that rules cannot express, such as lookups against a data store | Code can redirect on any condition and is easy to overlook in an audit |
Pages project _redirects file | Sites hosted on Cloudflare Pages | Lives in the site's code, not the dashboard; write the status on every line |
Cloudflare processes these features in a fixed order, documented in its developer documentation. When two of them match the same request, the one that runs first wins and the other may never be seen. That is why an old legacy rule can appear to be ignored, or can quietly override a newer one.
The fix, step by step
Step 1
Confirm Cloudflare is sending the redirect
Run the Redirect Checker on the problem URL and note each hop. Then request it with curl and look at the headers: a redirect with no application cookies, that still happens for a path your server does not have, and that leaves no line in your server access log, came from Cloudflare. If the origin sent it, fix it there instead, using the guide for your server or CMS, and leave Cloudflare alone.
Step 2
List every place that can redirect
Go
through the zone and write down every rule or setting that can redirect: single redirect rules, bulk
redirect rules and their lists, any legacy page rules with forwarding, the Always Use HTTPS setting,
Workers routes, and any Pages _redirects file. Record the match, the target, the status
code and whether query strings are kept. Include rules that are switched off, because someone may switch
them on again later.
Step 3
Give each job one Cloudflare feature
Decide which feature owns each job and write it at the top of your list. A sensible split is: the HTTPS upgrade in one place only, host and folder patterns in single redirect rules, long one-to-one lists in bulk redirects, and anything needing lookups or complex logic in a Worker. Any legacy forwarding rule should be recreated in the feature that owns its job and then switched off, not left running alongside.
Step 4
Build site-wide rules as single redirects
Create a redirect rule for the host change, for example matching requests where the
hostname equals example.co.uk and sending them to https://www.example.co.uk
followed by the original path, with a 301 and query strings kept. Use a dynamic target or a wildcard
pattern so the path is carried over. Give each rule a clear name, and put more specific rules above general
ones so they are reached first.
Step 5
Move one-to-one URL lists into bulk redirects
If you have dozens or hundreds of old addresses each mapped to a new one, put them in a bulk redirect list rather than one rule per URL. Upload them as a CSV with source, target and status, check the options for keeping query strings and matching subpaths, then create the bulk redirect rule that switches the list on. Make sure every target is a final URL, not another redirect source, so the list cannot create chains.
Step 6
Check proxy status and encryption mode
Edge redirects only run for hostnames whose DNS record is proxied, shown as an orange cloud. A redirect-only hostname still needs a proxied record. Then check the SSL/TLS encryption mode: if Cloudflare connects to your server over HTTP while the server forces HTTPS, you get a loop. Install a certificate on the origin and use the full, strict mode so both sides agree the connection is secure.
Step 7
Test, then remove the leftovers
Purge the cache for the affected URLs, then run the Redirect Checker on the four scheme and host combinations and a sample of old URLs from each list. Each should reach a 200 in one hop. Once they do, delete the legacy rules and disabled duplicates you replaced, and remove matching rules from the origin server, so only one layer answers each kind of request in future.
Example rules
The exact field names in the dashboard change from time to time, but the logic is stable. These are written in the form Cloudflare's rule expressions use.
Bare domain to www, keeping the path
When incoming requests match:
(http.host eq "example.co.uk")
Then:
Type: Dynamic
Expression: concat("https://www.example.co.uk", http.request.uri.path)
Status code: 301
Preserve query string: on
Old folder to new folder with a wildcard
Request URL: https://www.example.co.uk/blog/*
Target URL: https://www.example.co.uk/articles/${1}
Status code: 301
Preserve query string: on
A redirect-only domain
For an old domain that only needs to forward to the main site, add it to Cloudflare, create a proxied
DNS record for the bare name and www (Cloudflare's documentation suggests a placeholder
address such as 192.0.2.1 for this purpose), then add a single redirect rule sending both
hostnames to the matching path on the main domain.
A Worker for logic rules cannot express
export default {
async fetch(request, env) {
const url = new URL(request.url);
const target = await env.REDIRECTS.get(url.pathname);
if (target) {
return Response.redirect("https://www.example.co.uk" + target, 301);
}
return fetch(request);
}
};
Here REDIRECTS is a key-value store bound to the Worker. Use this only where rules and
bulk lists are not enough: code is harder for the next person to audit.
Cloudflare-specific pitfalls
- Grey-cloud records. A DNS-only record bypasses Cloudflare completely, so no rule
you write will run for that hostname. A common case is
wwwproxied and the bare domain not, or the other way round. - Two HTTPS upgrades. Always Use HTTPS at the edge and a force-HTTPS rule on the origin do not loop if the encryption mode is strict, but they do add work and confusion. Keep one.
- Flexible encryption. This mode encrypts only the visitor side. Any origin rule that forces HTTPS will then loop, and visitors' data travels unencrypted between Cloudflare and your server.
- Dropped paths. A static target such as
https://www.example.co.uk/sends every old URL to the homepage. Use a dynamic target or wildcard reference to carry the path over. - Query strings. Whether query strings are kept is an option per rule or list. Campaign tracking parameters are lost if it is off.
- Cached redirects. Redirect responses from the origin can be cached at the edge like any other response. Purge after changing origin redirects, or the old ones keep being served.
- Rule limits. Each plan allows a set number of rules and list entries. The limits change, so check your plan before designing a migration that needs thousands of entries.
Deciding between Cloudflare and your origin for each kind of rule is covered in fixing CDN and origin redirect conflicts, and building the list of old and new URLs for a site move is covered in the migration redirects guide.
Keeping Cloudflare redirects tidy
- Name every rule after what it does, such as "bare domain to www" or "2025 blog move", and add the date in the description.
- Keep one exported list of all bulk redirects outside Cloudflare, so you can review targets for chains and restore it if needed.
- Limit who can edit rules to the people who maintain the list, and check the account's audit log after unexplained changes.
- When you migrate away from a legacy feature, switch the old rule off for a week before deleting it, while you check the Redirect Checker results and Search Console for errors.
- Re-run the checker on the four scheme and host combinations after any change to DNS records, encryption mode or rules.
1. Should I use Cloudflare redirect rules or bulk redirects?
Use single redirect rules for patterns and site-wide behaviour: moving a whole host, a whole folder, or anything with conditions. Use bulk redirects for lists of individual old URLs, each mapped to its own new URL, which is typical after a migration. A pattern rule can replace thousands of list entries when the old and new addresses follow the same structure, so check for a pattern before uploading a long list. Many sites end up using both.
2. Are Cloudflare page rules still OK for redirects?
Existing page rules may still work, but Cloudflare has been moving customers to its newer rule features and has published guidance on migrating. Rules left in a legacy feature are easy to forget during audits and can override or duplicate newer rules. The safer course is to recreate each forwarding page rule as a redirect rule or bulk redirect entry, test it, then switch the old page rule off and delete it once you are sure it is not needed.
3. Why is my Cloudflare redirect rule not working?
The most common reasons are that the hostname's DNS record is not proxied, so traffic bypasses Cloudflare; that another feature which runs earlier, such as a legacy rule or a bulk redirect, matches first; that the match expression is slightly wrong, for example missing www or a trailing slash; or that a cached response from the origin is being served. Use the trace tool if your plan has it, and test with curl rather than a browser.
4. Why does Cloudflare cause ERR_TOO_MANY_REDIRECTS?
Usually because the encryption mode is set to flexible, so Cloudflare fetches pages from your server over plain HTTP, while your server or CMS forces HTTPS. The server keeps redirecting a request that the visitor made securely, and the browser gives up. Install a certificate on your server, switch to the full and strict encryption mode, and keep only one HTTPS rule. Conflicting www or slash rules between Cloudflare and the origin can also loop.
5. Can Cloudflare redirect a domain that has no website?
Yes. Add the domain to Cloudflare, create proxied DNS records for the names you want to redirect, and add a redirect rule that sends them to the matching address on your main site. Cloudflare's documentation describes using a placeholder address for the records, since no real server is needed. Remember that visitors who type https will need a certificate for the old domain, which Cloudflare issues for proxied hostnames in most setups.
6. Does a Cloudflare redirect keep the query string?
Only if you tell it to. Single redirect rules and bulk redirect lists each have an option to preserve the query string, and it may not be on by default. If it is off, tracking parameters and search terms in the old URL are dropped. For a dynamic target, you can also build the query string into the expression yourself. Check a test URL with a parameter such as ?utm_source=test in the Redirect Checker after each change.
The Redirect Checker follows each URL through its full chain, recording every status code, Location header and hop time, and flags long chains, loops, 302s that should be 301s, HTTPS gaps and mixed content.
Open Redirect Fixes โ