ERR_TOO_MANY_REDIRECTS on Cloudflare with Railway or Vercel
ERR_TOO_MANY_REDIRECTS behind Cloudflare's proxy usually means SSL/TLS mode Flexible. Use Full for Railway, Full (strict) for Vercel, then check redirects.
Why the browser says "redirected you too many times"
ERR_TOO_MANY_REDIRECTS on a domain proxied by Cloudflare (orange cloud) and hosted on Railway or Vercel is almost always Cloudflare's SSL/TLS encryption mode set to Flexible. In Flexible, Cloudflare talks to your host over plain HTTP, the host redirects HTTP to HTTPS, and the browser lands back on the same HTTPS address forever. Set the mode to Full for Railway or Full (strict) for Vercel, clear the browser's cached redirects and test again with curl -I.
If the mode is already right, the loop comes from two redirect rules that disagree: Always Use HTTPS or HSTS against an origin that sends HTTPS back to HTTP, or a Cloudflare redirect rule fighting a host or app redirect between the bare domain and www.
The exact messages
Each browser words it differently, but they all mean the same thing: the browser gave up after following a chain of redirects that never reached a page.
Chrome / Edge:
This page isn't working
example.com redirected you too many times.
ERR_TOO_MANY_REDIRECTS
Firefox:
The page isn't redirecting properly
Safari:
Too many redirects occurred trying to open "https://example.com/".How the Flexible loop works
Cloudflare has two connections to think about: visitor to Cloudflare, and Cloudflare to your origin. Cloudflare's documentation describes Flexible as HTTPS on the first and plain HTTP on the second. Full and Full (strict) use HTTPS on both, and Full (strict) also validates the origin's certificate.
Railway and Vercel both answer plain HTTP with a redirect to HTTPS. Vercel states that its HTTP to HTTPS redirect cannot be switched off. So under Flexible, every request Cloudflare forwards arrives as HTTP, gets told to go to HTTPS, and the browser asks Cloudflare for HTTPS again. Cloudflare's own troubleshooting page lists exactly this pairing, Flexible plus an origin that redirects to HTTPS, as the first cause of the error.
Causes at a glance
| Cause | How to recognise it | Fix |
|---|---|---|
| SSL/TLS mode is Flexible | Every hop in curl -IL is the same HTTPS URL | Full for Railway, Full (strict) for Vercel |
| Origin redirects HTTPS to HTTP | A Location: http:// header in the chain | Remove that redirect from the app or host |
| Always Use HTTPS or HSTS plus an origin HTTP redirect | Hops alternate between http:// and https:// | Remove the origin redirect, or turn the Cloudflare option off |
| Cloudflare rule against host or app redirect | Hops alternate between example.com and www.example.com | Keep one redirect, delete the other |
| Old redirect cached in the browser | curl shows a normal page, the browser still loops | Clear site data or test in a private window |
Confirm it with curl -I
Browsers hide the chain. curl shows each hop, so you can see whether the URL ever changes. Run the commands below with your own domain. The Location lines tell you where each response sends the client, and a cf-ray header shows the response came through Cloudflare.
The last two commands skip Cloudflare entirely by asking the host's own address. If those return a normal 200 while your domain loops, the host is fine and the problem sits in Cloudflare's settings or rules.
# Follow up to 10 redirects and print only the useful lines
curl -sIL --max-redirs 10 https://example.com | grep -iE '^(HTTP|location|cf-ray)'
# What does plain HTTP do?
curl -sI http://example.com | grep -iE '^(HTTP|location)'
# Ask the host directly, without Cloudflare
curl -sI https://your-service.up.railway.app
curl -sI https://your-project.vercel.appReading the output
- The same
https://example.com/repeated in everylocationline: Flexible mode. Cloudflare asks over HTTP and the host keeps sending it to HTTPS. https://andhttp://alternating: Always Use HTTPS or HSTS at Cloudflare, and something at the origin sending HTTPS back to HTTP.example.comandwww.example.comalternating: one layer redirects towwwand another redirects away from it.curl: (47) Maximum (10) redirects followed: confirms a loop. It does not tell you which layer, so read the lines above it.- A clean
200from curl while the browser still fails: the browser is replaying a cached permanent redirect. Clear the site's data or use a private window.
Fix 1: set the right SSL/TLS mode
In the Cloudflare dashboard, open the zone, go to SSL/TLS, then the Overview page, and choose the encryption mode. New zones may show Automatic SSL/TLS, where Cloudflare picks the most secure mode the origin supports. Cloudflare says Automatic will not move a zone to a less secure mode, so a zone that started on Flexible can stay there until you change it by hand.
For Railway, choose Full. Railway's SSL troubleshooting page says to use Full and not Full (strict). It explains that Full tolerates the temporary certificate states during Railway's certificate management, and lists error 526 as the symptom of strict mode. For Vercel, choose Full (strict). Vercel's guide on this error recommends it with a valid certificate on the Vercel side. Plain Full also stops the loop on Vercel, but it skips certificate validation.
The mode applies to the whole zone. If one zone fronts both Railway and Vercel, Full works for both.
Fix 2: Always Use HTTPS and HSTS
Always Use HTTPS lives under SSL/TLS, on the Edge Certificates page. It makes Cloudflare redirect every http request to https before it reaches your host. That is fine and usually what you want. It only causes a loop when the origin redirects HTTPS back to HTTP, which Railway and Vercel do not do on their own. Look for an app setting that forces a canonical http:// URL, such as a site URL variable left over from local development.
HSTS, on the same page, makes browsers rewrite links to HTTPS themselves. Cloudflare notes it loops if the encryption mode is Off or the origin redirects HTTPS to HTTP. Be careful turning it off as a test: browsers remember HSTS for the max-age you set, so the change does not take effect for returning visitors straight away.
Fix 3: redirect rules on two layers
The other classic loop is the bare domain and www. Vercel lets you set a domain to redirect to another, for example example.com to www.example.com, in the project's domain settings. If Cloudflare has a Redirect Rule or an old Page Rule sending www back to the bare domain, each layer undoes the other. Next.js redirects() in next.config and framework middleware can do the same.
Pick one place for each redirect and delete the copy. Cloudflare's guidance is to review redirect rules and Page Rules for conflicts. On Vercel, keeping the apex-to-www redirect in Vercel and having no Cloudflare rule for those hostnames is the simplest arrangement. On Railway, use either a single Cloudflare Redirect Rule or a redirect in the app, not both.
What Vercel recommends about the proxy
Vercel's guide to using Cloudflare is clear that it prefers direct connections. You can keep Cloudflare as the DNS provider and set the records Vercel shows to DNS only (grey cloud). Vercel lists the costs of proxying: its Bot Protection managed ruleset does not work behind a reverse proxy, it sees less about each visitor for security purposes, and a Vercel deployment does not clear Cloudflare's cache, which can leave stale HTML pointing at missing assets.
With the grey cloud, Cloudflare's SSL mode, Always Use HTTPS and redirect rules no longer touch the traffic, so this whole class of loop disappears. Vercel issues the certificate and does the HTTPS redirect itself. If you need Cloudflare's proxy features on a Vercel site, keep Full (strict) and read Vercel's notes on its Verified Proxy setting.
Railway behind the orange cloud
Railway supports proxied custom domains, and its docs say DNS lookups then show Cloudflare addresses rather than the Railway CNAME, which is expected. Its SSL page names a mismatched Cloudflare SSL mode as the usual cause of ERR_TOO_MANY_REDIRECTS and gives one fix: set the mode to Full.
Two related errors sit next to this one. Error 525 means Cloudflare could not complete the TLS handshake with Railway, often because Railway has not issued the certificate yet. Error 526 means Cloudflare rejected the certificate, which is the Full (strict) problem. Railway's suggestion for a domain that will not get a certificate while proxied is to turn the proxy off, wait for Railway to issue it, then turn the proxy back on. If the domain itself is stuck before that point, see our page on Railway stuck on "Waiting for DNS update".
The fix order
- Run
curl -sIL --max-redirs 10against the domain and note which pattern thelocationlines show. - Run
curl -sIagainst theup.railway.apporvercel.appaddress. If that loops too, the problem is in your app or host settings, not Cloudflare. - In Cloudflare, set SSL/TLS mode to Full (Railway) or Full (strict) (Vercel).
- Check the Edge Certificates page. Leave Always Use HTTPS on, and remove any app or host setting that sends HTTPS visitors to
http://. - List your Cloudflare Redirect Rules and Page Rules, then the host's domain redirects and your framework's redirects. Keep one redirect per hostname.
- Clear the site's data in the browser, or open a private window, and test again.
- On Vercel, consider switching the records to DNS only, which removes Cloudflare from the request path.
Preventing it on the next domain
Decide before launch whether a domain needs the proxy at all. Most small apps on Railway or Vercel do not: both hosts issue certificates and redirect to HTTPS themselves. If you do proxy, set the SSL mode first and add redirect rules last, testing with curl -I after each change.
Shipyard writes the Railway or Vercel records into Cloudflare as DNS-only, which keeps the host in charge of HTTPS and avoids this loop from the start. You can also check what a domain's records resolve to with our DNS check tool.
Sources
- Cloudflare docs: ERR_TOO_MANY_REDIRECTSdevelopers.cloudflare.com
- Cloudflare docs: Encryption modesdevelopers.cloudflare.com
- Cloudflare docs: Always Use HTTPSdevelopers.cloudflare.com
- Cloudflare docs: HTTP headers (Cf-Ray)developers.cloudflare.com
- Vercel KB: Resolve ERR_TOO_MANY_REDIRECTS when using Cloudflare proxy with Vercelvercel.com
- Vercel KB: Cloudflare with Vercelvercel.com
- Railway docs: Troubleshooting SSLdocs.railway.com
Launch in an hour, not a weekend
Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.