Proxies and CDNs · Practical guide
How to fix redirect loops behind a proxy or CDN
An HTTPS URL redirecting back to itself behind a CDN often indicates disagreement about the public scheme. A browser can use HTTPS while the application receives HTTP from a proxy. Mistaking that internal connection for the visitor’s scheme can produce a redirect back to the current URL. Identify the encryption mode and trusted request metadata before changing rules.
Recognize an HTTPS URL redirecting to itself
With Cloudflare Flexible encryption, a visitor can connect to the edge over HTTPS while Cloudflare connects to the origin over HTTP. An origin rule that redirects every HTTP request to HTTPS then returns the same public URL. The browser retries it, and the edge again uses HTTP to the origin.
The public trace can repeat HTTPS throughout: internal HTTP is not another browser-visible hop. Confirm Flexible mode and the origin rule; a mistaken application base URL can produce a similar symptom.
# Public response
GET https://example.com/account
301 Location: https://example.com/account
# Internal path in this example
Browser -- HTTPS --> Cloudflare -- HTTP --> origin
Origin sees HTTP and redirects to the same public HTTPS URL. - Trace the exact failing public URL and capture its repeated status and Location without session secrets.
- Check the edge encryption mode and correlate that request with the origin redirect rule.
- Prepare working origin HTTPS and correct scheme handling, then retest the public URL after deployment.
Compare transport with the original visitor scheme
Map the route through the CDN, load balancer, web server and application. Compare the public HTTPS URL, each internal connection’s transport and the forwarded scheme reaching the application. Cloudflare sets X-Forwarded-Proto to the visitor’s protocol and overwrites a conflicting incoming value.
Correlate a request identifier with temporary diagnostic logs containing the effective host, transport scheme, forwarded scheme and redirect decision. Use a harmless path and redact query values, credentials and cookies. The presence of a forwarded header is not enough: record whether the application trusted its sender and interpreted the request as secure.
A direct origin request bypasses the edge. If your operator performs one, preserve the intended hostname and TLS SNI and validate the certificate. A bare IP can select another virtual host; disabling certificate verification hides useful evidence.
Reference: Cloudflare: forwarded protocol and request identifiers
Make origin HTTPS work before enabling Full (strict)
For Cloudflare, prepare the origin before moving from Flexible to Full (strict). It must accept HTTPS on port 443 and present an unexpired certificate matching the requested or target hostname, issued by a publicly trusted CA or Cloudflare Origin CA. A certificate problem can replace the loop with a 526 error.
An Origin CA certificate protects Cloudflare-to-origin traffic; ordinary browsers do not trust it directly. Account for that when testing. Keep verification enabled and arrange renewal. Once origin HTTPS works, change the mode and confirm public HTTPS no longer triggers the upgrade rule.
Also remove a conflicting origin rule that sends HTTPS back to HTTP. Turning visitor TLS off or bypassing certificate checks is not a correction for mismatched scheme detection. Full (strict) secures and verifies the origin connection; it does not fix every application or hostname redirect.
Reference: Cloudflare: Full (strict) requirements
Trust scheme headers only across a controlled proxy path
The application should trust forwarded metadata only from the actual proxy addresses that can connect to it. Restrict origin access appropriately and make the trusted boundary overwrite untrusted client values. Do not fix a loop by trusting every sender or treating any client-supplied X-Forwarded-Proto: https as authoritative.
In Laravel 13, configure trustProxies in bootstrap/app.php. This scheme-only example belongs inside the existing withMiddleware callback. Substitute the verified connecting proxy address and preserve other validated forwarded-header requirements; this is not a complete replacement configuration.
If Nginx terminates visitor TLS, proxy_set_header X-Forwarded-Proto $scheme can describe that connection. If Nginx instead receives HTTP from an earlier TLS-terminating proxy, $scheme describes that internal HTTP hop. Preserve the validated original scheme across the known chain instead of overwriting it blindly. Recheck the actual application interpretation.
// Inside the existing withMiddleware callback in bootstrap/app.php
// Replace this example with the actual trusted connecting proxy.
$middleware->trustProxies(
at: ['10.0.0.10'],
headers: \Illuminate\Http\Request::HEADER_X_FORWARDED_PROTO,
); Reference: Laravel 13: configuring trusted proxies
Verify the corrected public route and trust boundary
Use a bounded GET trace through the public hostname after the change. The command below follows at most ten redirects and stops after thirty seconds. Query values and response cookies in curl output are not redacted. RedirectPath redacts query values, so identical displayed URLs alone are not conclusive when their hidden values differ.
RedirectPath follows up to ten HTTP redirects without cookies or JavaScript. Check its stop reason: a limit is different from a detected repeated request. Use a real browser separately for authenticated flows and confirm the destination contains the intended page.
curl -q -sS -L --max-redirs 10 --max-time 30 \
-D - -o /dev/null \
'https://example.com/account' - Trace HTTP and HTTPS entry points and supported host aliases; they should reach the intended HTTPS resource.
- Test a deep path, an asset and the actual sign-in journey without removing required authentication redirects.
- Confirm in a controlled test that requests outside the trusted proxy path cannot spoof the application’s scheme.
- Confirm the public response after CDN cache updates and remove temporary diagnostic logging.
Reference: curl: bounded redirect tracing
Keep reading
Related guides
301 vs 302 vs 307 vs 308 redirects
Choose a redirect status with a practical decision table, then verify GET, POST, caching and the final destination.
Read guide TroubleshootingHow to find and fix redirect chains and loops
Read redirect traces, identify conflicting www or trailing-slash rules, and repair chains without losing the page, path or required query parameters.
Read guide HTTPS migrationsAn HTTP to HTTPS redirect checklist
Redirect HTTP to HTTPS without losing paths or query parameters. Check Nginx rules, www certificates, mixed content and HSTS readiness.
Read guide Browser diagnosticsHTTP redirects vs JavaScript and meta refresh
Find why a browser navigates after a 200 response, distinguish HTTP redirects from scripts and refresh, and verify the right fix.
Read guide Domain migrationsHow to check redirects during a domain migration
Map old URLs to useful new destinations, preserve important parameters and verify TLS, redirects, page content and Google Search signals.
Read guideHTTP status code reference for redirects and endpoints
Compare 301, 302, 303, 307 and 308, then interpret common endpoint errors and redirect stop reasons.
Open reference