When a cPanel-hosted site loops behind Cloudflare, the origin is almost always redirecting based on something the edge has already changed. Under Flexible SSL the origin only ever sees HTTP, so an .htaccess rule testing %{HTTPS} redirects to HTTPS forever. The fix is to switch the zone to Full (strict) so the origin actually receives HTTPS, or to make the origin rule read X-Forwarded-Proto instead of the local connection — and to remove the duplicate redirects cPanel likes to stack up.
What’s happening
Four layers can issue the redirect, in this order: the browser cache replays a stored 301 without touching the network; the Cloudflare edge answers next — Always Use HTTPS first, then Redirect Rules, but only on proxied (orange-cloud) hostnames; then the origin, which on cPanel means the Apache or LiteSpeed vhost, the Domains-interface redirect and Force HTTPS toggles, and every .htaccess from the docroot up; finally the application (WordPress and friends).
The loop mechanics are simple: Cloudflare terminates TLS for the visitor, and in Flexible mode fetches from the origin over plain HTTP. The origin’s scheme test (RewriteCond %{HTTPS} off) is true on every single request, so it 301s to https://, which Cloudflare fetches over HTTP again. A second variant is host disagreement: an edge rule canonicalizes to www while an .htaccess rule or cPanel Domains redirect canonicalizes to the apex, and the two bounce the visitor back and forth. The generic server-side anatomy of this failure is covered in cPanel too-many-redirects; this article is the Cloudflare-specific layer on top.
What to check first
- SSL/TLS mode on the zone. Flexible plus any origin force-HTTPS rule is a guaranteed loop.
- How many redirect owners exist on the origin: the cPanel Domains redirect list, the Force HTTPS Redirect toggle, and hand-edited
.htaccessrules are three separate mechanisms that people enable in parallel. - Whether the record is proxied. Grey-cloud means the edge never runs and this is a pure origin problem.
- Test with curl. A browser that saw the loop keeps replaying cached 301s after the fix.
How to verify
Walk the chain from outside and watch the Location values alternate or repeat:
curl -sIL --max-redirs 5 https://example.com/ | grep -iE 'HTTP/|location|cf-ray|cf-cache-status'
Attribute a single hop: a 301 with server: cloudflare, a cf-ray, and no cf-cache-status came from the edge; a redirect carrying cf-cache-status: DYNAMIC (or HIT) passed through from — or was cached from — the origin.
curl -sI https://example.com/ | grep -iE 'HTTP/|location|server|cf-ray|cf-cache-status'
Now bypass Cloudflare and ask the origin itself, on both ports (-k because the origin may hold a self-signed or Origin CA certificate):
curl -sI --resolve example.com:80:203.0.113.10 http://example.com/ | grep -iE 'HTTP/|location'
curl -skI --resolve example.com:443:203.0.113.10 https://example.com/ | grep -iE 'HTTP/|location'
If the port-80 probe 301s to HTTPS and the port-443 probe 301s back to HTTP or to a different host, you have found the disagreement. Then inventory the origin’s redirect rules:
grep -RinE 'RewriteRule|RewriteCond|^Redirect' ~/public_html/.htaccess
The fix
-
Switch the zone to Full (strict). Run AutoSSL (or install an Origin CA certificate) so the origin serves valid TLS, then change the mode in SSL/TLS. The origin now receives real HTTPS requests,
%{HTTPS}evaluates correctly, and the classic loop ends. Cloudflare’s SSL docs treat Flexible as a legacy compromise — so should you. -
Make any remaining origin scheme rule proxy-aware. If a rule must stay in
.htaccess, key it on the forwarded protocol, not the local socket:RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]This behaves correctly both behind the proxy and if the record is ever grey-clouded.
-
Collapse to one redirect owner per decision. Let the edge own the HTTP-to-HTTPS hop (Always Use HTTPS) and pick one place for host canonicalization. Delete the equivalents from the cPanel Domains redirect list and the
.htaccess; the layering rules are laid out in redirects: UI vs .htaccess vs vhost. -
Make the host decision consistent. If the edge sends visitors to
www, no origin rule may send them back to the apex. Grep for both forms before closing the ticket. -
Purge and retest. Purge the Cloudflare zone (a looping 301 may be cached), retest with the curl walk, then confirm in a fresh private window.
When this fix is wrong
- No
cf-rayon any response. The hostname is DNS-only; Cloudflare is not in the path and the loop is purely origin-side. - You see 522 or 525/526 instead of a loop. That is connectivity or TLS handshake failure to the origin, a different failure class entirely.
- The loop only exists on one URL or section. Look for an application-level rule (plugin, CMS canonical) rather than a global scheme or host rule.
Common mistakes
- Editing the wrong
.htaccess. Apache merges every.htaccessfrom the docroot upward, and addon-domain docroots often sit insidepublic_html, inheriting the parent’s redirect rules. - Enabling cPanel’s Force HTTPS toggle on top of a hand-written rule. Two owners for the same hop; they eventually disagree on host or slash and loop.
- Testing only in a browser. Cached 301s make a fixed site look broken and a broken site look intermittent.
- Writing the
X-Forwarded-Protocondition but leaving the old%{HTTPS}rule above it. The first matching rule wins; dead rules must be removed, not appended to. - Fixing the loop under Flexible and calling it done. The origin leg is still unencrypted; the actual fix is Full (strict), as detailed in HTTP to HTTPS in .htaccess.
Prevention
Make Full (strict) plus AutoSSL the standard for every cPanel zone you put behind Cloudflare. Keep exactly one owner per redirect decision — edge for scheme, one named place for host — and write proxy-aware conditions on any origin rule that must exist. Add a four-variant curl walk (http/https times www/apex) to the change checklist so a reintroduced loop is caught in seconds, not by customers.
If redirects keep fighting each other across Cloudflare, the origin, and the CMS, Stack Harbor untangles that chain as part of Managed Cloud Ops — book an infrastructure review.