All articles
7 min read

Redirect chains: how to check them, and the one HTTP-to-HTTPS redirect you actually want

How to check a redirect chain hop by hop, with a free redirect checker or curl. Why long chains, temporary redirects and loops cause trouble, what a clean HTTP-to-HTTPS (SSL) redirect looks like, and how to notice when it breaks.

Free toolFollow any URL through its redirects now

Most sites carry a few redirects nobody remembers adding. One came with the hosting panel, one with the CDN, one with a plugin installed years ago, and one is the line in the app that forces HTTPS. Each is reasonable on its own. Stacked, they can bounce a visitor who types example.com through four addresses before the real page starts to load. The browser follows along without a word, so you never see it unless you look at the hops.

Look at the hops, not the page

The quickest way is our free redirect checker. Paste the address the way people actually type or link it, which usually means plain http:// and no www. It sends a normal GET, reads headers only, follows up to five redirects and gives up after 8 seconds. You get every hop with its status code and Location header, plus the URL it lands on. It also points out what it can tell from the hops alone: an http:// to https:// upgrade, a hop from https:// back to http://, a temporary redirect, more than two hops, or a chain it had to stop following.

From a terminal, curl shows the same chain. -I asks for headers only and -L follows redirects, so you get one header block per hop:

bash
curl -sIL http://example.com

# Some servers answer HEAD differently from GET. If the result looks odd,
# send a real GET and print only the summary:
curl -s -o /dev/null -L \
  -w '%{http_code} after %{num_redirects} redirects -> %{url_effective}\n' \
  http://example.com

Run it for all four entry points, not just the one you think of as “the site”: http://example.com, http://www.example.com, https://example.com and https://www.example.com. Old backlinks, bookmarks and typed URLs arrive through all four, and the chains are often different. The www variant without HTTPS is the one most often forgotten.

What a clean chain looks like

text
http://example.com        301 -> https://example.com/
https://example.com/      301 -> https://www.example.com/
https://www.example.com/  200

Two hops, both permanent, both moving in the same direction, and the final address answers 200 without redirecting anywhere. You could send http://example.com straight to https://www.example.com/ and save a round trip. The reason not to: the HSTS preload list at hstspreload.org asks that the first redirect go from HTTP to HTTPS on the same host. The two-hop version keeps that option open. Either choice is fine, as long as it's a choice.

Where chains go wrong

Too many hops

A typical accidental chain: http://example.com to https://example.com to https://www.example.com to https://www.example.com/en to https://www.example.com/en/. Every step is somebody's sensible rule. The host forces HTTPS, the CDN adds www, the app picks a language, the framework appends a slash. Each hop is one more round trip before the page starts loading, and crawlers have a ceiling: Google says Googlebot follows up to 10 hops, and other crawlers may give up sooner. The fix is dull but effective. Point the first redirect straight at the final URL, and make internal links, the sitemap and canonical tags use the final URL so they never trigger a redirect at all.

Temporary where you meant permanent

302, 303 and 307 say “this is temporary”. For Google that's only a weak hint that the target should replace the old address, so the old URL can hang around in search results. If the move is final, use 301 or 308. The only difference between those two is that 308 tells the client to keep the request method, which matters for form posts and APIs and hardly at all for an ordinary page. Plenty of frameworks and hosting panels default to 302, so it's worth checking even when you're sure you configured a 301.

Back from https:// to http://

Somewhere in the middle, a hop sends the visitor from https:// back to http://. Usually an old rule or a hard-coded base URL still says http. That hop travels unencrypted, browsers may warn about it, and if HSTS is on, the browser upgrades it again and you've just added another hop. The redirect checker flags this one explicitly.

Loops

A sends you to B, B sends you back to A. The browser eventually gives up with “too many redirects” (ERR_TOO_MANY_REDIRECTS in Chrome). Our checker stops after five redirects and says so instead of pretending the chain ended. Look at the last few hops and you'll usually see the same two URLs taking turns.

The loop that shows up the day you add a CDN

The most common loop isn't caused by a wrong rule. Every rule is right; they just disagree about how the request arrived. Your CDN or load balancer terminates HTTPS and talks to the origin over plain HTTP. The origin sees an http:// request and, as instructed, redirects to https://. The browser follows that back to the CDN, which talks HTTP to the origin again, which redirects again. Cloudflare's “Flexible” SSL mode is the textbook case, because it connects to your origin over HTTP by design.

  • Let the edge talk HTTPS to the origin, so the origin never sees a plain HTTP request from it.
  • Or have the origin trust the proxy's X-Forwarded-Proto header and only redirect when it says http. Most frameworks and web servers call this a “trusted proxies” or “behind a proxy” setting.
  • Force HTTPS in exactly one layer. If the CDN has an “always use HTTPS” switch on, the origin doesn't need its own rule, and the other way round.

The HTTP-to-HTTPS redirect you actually want

Out of all the redirects on a site, this is the one worth keeping: a single permanent hop from http:// to https:// on the same host, keeping the path and query string. On nginx that's a port-80 server block that does nothing else:

nginx
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

$host keeps the hostname the visitor asked for, and $request_uri keeps the path and query. Leave out $request_uri and every deep link lands on your homepage, which is a quiet way to throw away old backlinks. Put the www or non-www redirect in the HTTPS server block. On Apache the equivalent is a RewriteRule with [R=301,L] guarded by RewriteCond %{HTTPS} off. Behind a proxy that terminates TLS, %{HTTPS} is always off on the origin, which is exactly the loop from the section above.

Once the redirect is solid, send HSTS on your HTTPS responses. A browser that has seen this header goes straight to https:// for the time given and skips the http:// hop on later visits:

http
Strict-Transport-Security: max-age=31536000; includeSubDomains

Start with a short max-age while you test: the browser remembers it for the full duration and you can't take it back early. Only add includeSubDomains once every subdomain really serves HTTPS. Our HTTP header checker shows whether the header actually goes out. One side effect that trips people up: HSTS and cached 301s live in the browser. If you've fixed a redirect and your laptop still misbehaves, check from somewhere else before you change anything else.

A broken redirect is an outage

Redirects rarely break on their own. They break when someone changes something: a domain move, a CDN switch, a new language prefix, a rule meant to be temporary. To a visitor it looks exactly like downtime, even though every server involved is answering happily. An HTTP monitor catches this, but only if you set it up for it, so here is how HyperMonitors behaves.

By default an HTTP monitor follows up to five redirects and judges the response at the end. With “Expected status codes” left blank, any 2xx or 3xx counts as up. So a loop that is still redirecting after five hops ends on a 3xx and is not reported as down. If the URL should end on a real page, enter 200.

  • To know the chain lands on the right page and not just some page, add a keyword that only appears on the destination and set it to “must be present”. A redirect that suddenly points at the homepage or a parked domain then fails as well.
  • To watch the redirect itself, add a second monitor for the old address (say http://example.com), switch “Follow redirects” off and set the expected status code to 301. If someone turns it into a 302 or removes it, you'll hear about it. This checks the status code only, not where Location points, so keep the first monitor on the final URL too.
  • All of this works on the free plan: HTTP monitors, expected status codes, keywords and the redirect switch are included, with up to five monitors checked at most every five minutes.

When a check fails, a probe in another region checks again before the monitor is marked down, so a single flaky hop on one network doesn't wake anyone up.

The short version

  • Run all four entry points through the redirect checker or curl -sIL.
  • Aim for one or two permanent hops pointing the same way and ending on a 200.
  • Swap 302s for 301s where the move is final, and remove any hop back to http://.
  • If a loop appears right after adding a CDN, look at how the edge talks to your origin before touching your rules.
  • Monitor the final URL with an expected 200, and the old address with Follow redirects off if it matters.
Monitoring that tells you before your customers do

Websites, APIs, ports, DNS, certificates and cron jobs. A failed check is re-checked from another region before you are alerted. The free plan includes 5 monitors, each from one region.

Start monitoring free