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.

Simon, Founder of Shipyard

By · Founder of Shipyard

7 minute read

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.

Text
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

CauseHow to recognise itFix
SSL/TLS mode is FlexibleEvery hop in curl -IL is the same HTTPS URLFull for Railway, Full (strict) for Vercel
Origin redirects HTTPS to HTTPA Location: http:// header in the chainRemove that redirect from the app or host
Always Use HTTPS or HSTS plus an origin HTTP redirectHops alternate between http:// and https://Remove the origin redirect, or turn the Cloudflare option off
Cloudflare rule against host or app redirectHops alternate between example.com and www.example.comKeep one redirect, delete the other
Old redirect cached in the browsercurl shows a normal page, the browser still loopsClear 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.

Terminal
# 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.app

Reading the output

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

  1. Run curl -sIL --max-redirs 10 against the domain and note which pattern the location lines show.
  2. Run curl -sI against the up.railway.app or vercel.app address. If that loops too, the problem is in your app or host settings, not Cloudflare.
  3. In Cloudflare, set SSL/TLS mode to Full (Railway) or Full (strict) (Vercel).
  4. Check the Edge Certificates page. Leave Always Use HTTPS on, and remove any app or host setting that sends HTTPS visitors to http://.
  5. List your Cloudflare Redirect Rules and Page Rules, then the host's domain redirects and your framework's redirects. Keep one redirect per hostname.
  6. Clear the site's data in the browser, or open a private window, and test again.
  7. 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

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.

Get started See how it works

Read next