Skip to content

Always Use HTTPS vs origin redirects: who should own the HTTP to HTTPS hop

The HTTP to HTTPS redirect can come from the Cloudflare edge, the origin server, or a CMS plugin — and sites often run all three. Here is who should own the hop, how to audit the chain, and how to retire the duplicates safely.

On a proxied Cloudflare zone, the edge should own the HTTP to HTTPS hop: turn on Always Use HTTPS and let it issue the 301 before the request touches cache or origin. The origin keeps at most a proxy-aware backstop rule for direct or grey-cloud access, and CMS-level scheme redirects go away entirely. Sites that let all three layers redirect end up with two- and three-hop chains — or, under Flexible SSL, a loop.

What’s happening

Four layers can issue the scheme redirect, in evaluation order: the browser cache (a stored 301 replays with no request), the Cloudflare edge, the origin server, and the CMS. At the edge, Always Use HTTPS runs before Redirect Rules — which cuts both ways: it guarantees the upgrade happens before any other logic, and it means a Redirect Rule keyed on http.request.scheme eq "http" never fires while the toggle is on, because no HTTP request survives long enough to reach it.

Duplicated ownership is what creates chains. A typical accumulation: Always Use HTTPS upgrades http://example.com to https://example.com (hop one), a host rule sends it to https://www.example.com (hop two), and the CMS adds a trailing slash (hop three). Each hop is a full round trip for first-time visitors and another URL for crawlers to track. Under Flexible SSL it gets worse: the origin only ever sees HTTP, so an origin-level force-HTTPS rule fights the edge forever — the classic loop.

What to check first

  • Is Always Use HTTPS already on? SSL/TLS, then Edge Certificates. Note what else redirects: origin .htaccess or vhost rules, and any CMS SSL plugin.
  • What SSL mode is the zone in? Under Flexible, origin scheme rules are loop bait; under Full (strict) they are merely redundant.
  • Is HSTS enabled, and did someone enable it before the chain was clean?

How to verify

Audit the chain from all four entry variants and count hops:

for u in http://example.com https://example.com http://www.example.com https://www.example.com; do
  printf '%-30s ' "$u"
  curl -sIL -o /dev/null -w '%{num_redirects} hops -> %{url_effective}\n' "$u/"
done

Attribute each hop. An Always Use HTTPS redirect shows server: cloudflare, a cf-ray, and no cf-cache-status; an origin redirect passing through the proxy carries cf-cache-status: DYNAMIC (or HIT if cached); a CMS hop often labels itself with x-redirect-by:

curl -sI http://example.com/ | grep -iE 'HTTP/|location|server|cf-ray|cf-cache-status|x-redirect-by'

Then ask the origin what it does on port 80 without the edge in the way:

curl -sI --resolve example.com:80:203.0.113.10 http://example.com/ | grep -iE 'HTTP/|location'

The fix

  1. Turn on Always Use HTTPS at the edge. SSL/TLS, Edge Certificates, Always Use HTTPS. This issues a zone-wide 301 for every HTTP request on proxied hostnames, before cache and origin. Pair it with Full (strict) so the origin leg is encrypted too; Cloudflare’s SSL documentation covers both settings.
  2. Demote the origin rule to a proxy-aware backstop. Keep one rule for direct access and grey-cloud days, conditioned on the forwarded protocol (RewriteCond %{HTTP:X-Forwarded-Proto} !https) so it stays inert behind the proxy. The origin-side pattern is written up in HTTP to HTTPS in .htaccess. Delete any rule that tests %{HTTPS} bare.
  3. Remove CMS-level scheme redirects. Force-HTTPS toggles in SSL plugins duplicate the edge hop and add latency at the slowest layer. The CMS should simply generate HTTPS URLs.
  4. Collapse the chain. Make the host-canonicalization rule target the final form directly (https://www.example.com plus path), so the worst entry point costs two hops and the common ones cost one or zero. If you need one hop from every entry, a single combined rule matching (http.host eq "example.com") or (http.request.scheme eq "http") can replace Always Use HTTPS — but then that rule alone owns HTTPS enforcement, so document it.
  5. Finish with HSTS. Once every variant lands clean, HSTS makes returning browsers skip the HTTP hop entirely; rollout order and the risks are covered in HSTS, Always Use HTTPS and edge certificates.

When this fix is wrong

  • The hostname is grey-cloud. Always Use HTTPS only acts on proxied traffic; for DNS-only hosts the origin must own the hop, full stop.
  • One legacy hostname must stay on HTTP (an old device endpoint, a plaintext health check). Zone-wide Always Use HTTPS has no exceptions — leave it off and write a scoped Redirect Rule upgrading only the hostnames that should move.
  • The symptom is mixed-content warnings, not redirects. That is page content loading HTTP assets on an HTTPS page — a content fix (or Automatic HTTPS Rewrites), not a redirect-ownership problem.

Common mistakes

  • Writing a scheme Redirect Rule while Always Use HTTPS is on, then concluding rules are broken because it never fires. It is shadowed, not broken.
  • Keeping a bare %{HTTPS} off rule under Flexible SSL — the origin never sees HTTPS, so the rule loops the moment the edge is bypassed into it.
  • Letting the scheme hop and the host hop stay separate forever. Two permanent hops on every http://apex entry is pure latency; collapse them once traffic patterns are known.
  • Enabling HSTS with includeSubDomains before auditing subdomains, breaking grey-cloud hosts that still serve HTTP.
  • Trusting a browser test. Cached 301s and HSTS pins in your own browser misreport the live chain; audit with curl.

Prevention

Write the ownership decision into the runbook: edge owns scheme (Always Use HTTPS on, Full (strict) mode), origin keeps one proxy-aware backstop, CMS redirects nothing. Re-run the four-variant hop count after any DNS, TLS-mode, or rule change — it takes ten seconds and catches regressions the same day they ship.

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.