---
title: "Why Does a Proxy Cause a Redirect Loop? Diagnosis and Fix"
description: "A proxy redirect loop usually comes from a cookie that is never stored or an exit IP that changes mid-chain. How to read the chain step by step and fix it."
url: https://proxynet.io/blog/proxy-redirect-loop
date: 2026-12-01
author: "Acar Diveroli"
category: "Tutorial"
lang: en
---

# Why Does a Proxy Cause a Redirect Loop? Diagnosis and Fix

A redirect loop is a chain of 3xx responses that eventually sends the client back to the same address. The client follows the chain up to a limit, then fails. A browser reports it as `ERR_TOO_MANY_REDIRECTS`, Requests as `TooManyRedirects`, curl as `Maximum (50) redirects followed`. With a proxy, the two typical causes sit on the client side: the cookie is not stored, or the exit IP changes in the middle of the chain. This post covers those causes, how to read the chain step by step, and how we fixed the loops we reproduced on a local server.

> **Note: Short answer**
>
> A redirect loop is a 3xx chain that returns to the same address. With a proxy, the two typical causes are a cookie that is not stored and an exit IP that changes mid-chain: a cookie jar fixes the first, a sticky session the second.

## Anatomy of a loop

When a server returns 301, 302, 303, 307 or 308 with a `Location` header, the client goes to the new address. 301 and 308 signal a permanent move, 302 and 307 a temporary one. 303 points to the result at another address. In a loop, the chain never ends with a 200. Page A sends you to B, and B sends you back to A.

The HTTP standard asks clients to detect such loops and stop. Each tool does this with its own limit:

| Tool | Default limit | What you see in a loop |
|---|---|---|
| Chrome, Node `fetch` | 20 | `ERR_TOO_MANY_REDIRECTS`, in Node `redirect count exceeded` |
| Requests | 30 | `TooManyRedirects: Exceeded 30 redirects.` |
| HTTPX | 20, redirects off by default | `TooManyRedirects: Exceeded maximum allowed redirects.` |
| curl | 50, only with `-L` | `curl: (47) Maximum (50) redirects followed` |
| Python `urllib` | 10, same address 4 times | `HTTPError 302: … would lead to an infinite loop` |

Raising the limit does not fix a loop. It only makes the error arrive later. To see what goes around in the chain, turn redirects off and read the steps one by one.

## A cookie that is not stored

The typical setup is a gate page. It sends you from `/account` to `/consent`, sets a session cookie there with `Set-Cookie`, and sends you back. If the client does not send the cookie on the next request, the server treats you as a new visitor. The chain returns to `/consent`.

We built this setup on a local server and tried the tools one by one. curl does not store cookies unless its cookie engine is on, even with `-L`. In our test it bounced between `/account` and `/consent` for 50 steps. Python `urllib` and Node's built-in `fetch` also looped. Requests `get` and HTTPX with `follow_redirects=True` carried the cookie through the chain of a single call and got a 200.

This Requests behaviour is limited to one call. Every `requests.get` starts with a fresh session, so the cookie does not reach the next call. To keep cookies between calls, use `requests.Session`. The session setup is covered in detail in [Sessions and Cookies in Python](/blog/python-login-session-cookies).

In curl, turn the cookie engine on with a file. `-c` writes incoming cookies to the file, `-b` reads them from the same file:

```bash
curl -L --max-redirs 10 \
  -c cookies.txt -b cookies.txt \
  -x http://user:pass@pr.proxynet.io:8000 \
  http://site.example/account
```

If you do not want a file, write `-b ""`. According to the curl documentation, an empty value starts the cookie engine without any cookies. In our test both forms ended the loop and the page came back with a 200.

## An IP that changes mid-chain

Some sites bind the session cookie to the IP address it was first seen from. A rotating proxy gives a different exit IP on every new request. Each step of the chain is a separate request, so the cookie comes back from a different IP than the one it was set for. The server rejects it, sets a new one and sends you back to the gate.

Here a cookie jar alone is not enough. In our test `requests.Session` sent the cookie correctly at every step. Through a local proxy that changed the source address on every request, it still hit `TooManyRedirects` after 30 steps. Through a proxy that kept the address fixed, the same code got a 200 after two redirects.

The symptom is clear. Every round of the chain brings a new `Set-Cookie` value, and the cookie is rejected even though it was sent. The fix is to keep the same exit IP until the flow ends. [Sticky Proxy](https://proxynet.io/sticky-proxy) keeps a session on the same IP for 1-60 minutes.

Requests has one more trap. It picks the proxy for each step based on that step's scheme. If the `proxies` dict has only an `http` key and no environment variable is set, the step that redirects from an `http://` address to an `https://` address goes out without the proxy, from your own IP. Half of the chain appears to come from another address. Put the same value under both keys.

## Country-based redirects

Regional sites send visitors to the local version that matches the country of their IP address. A visitor who requests `/de/` with a Türkiye IP is redirected to `/tr/`. If the IP switches back to Germany on the next step, `/tr/` sends them to `/de/` again. How a location is derived from an IP is explained in [What Is Geo-Blocking?](/blog/what-is-geo-blocking)

Our test server treated two local addresses as two different countries. The proxy handed out these two addresses in turn. The result depended on which address the first request landed on. In one run the page came straight back with a 200, in the other HTTPX raised `TooManyRedirects`. In a real pool the IP order is random, so this loop shows up intermittently: the same command sometimes works and sometimes fails.

The fix is again a fixed IP. On top of that, the country of the page you request and the country of the exit IP should match. Request the Türkiye version with a Türkiye IP. If a site deliberately keeps a region out, do not try to get around it through redirects. Use the site's official API or ask for permission.

## Scheme, www and relative addresses

A redirect from `http://` to `https://`, or from the bare domain to `www`, is normally a single step. If these steps turn into a loop, the site has two conflicting rules. Only the site owner can fix that. The site-side causes are collected in [How to Fix err_too_many_redirects](/blog/err-too-many-redirects).

One trap visible from the client is a host-bound cookie. A cookie set without a `Domain` attribute goes back only to the host that set it. In our test the gate page set a cookie on `localhost` and redirected to `127.0.0.1`. The cookie jar worked correctly, but the cookie never reached the other host. Both `requests.Session` and curl with a cookie file looped. If two hosts alternate in the chain, the problem is not on your side.

`Location` can also be a relative address. Under RFC 9110, a relative address is resolved against the address of the request. In our test, `../c` returned by `/relative/a/b` resolved to `/relative/c`. If you follow the chain by hand, resolve the relative address against the last requested address, not the first one. A wrong base produces a fake loop that leads back to the same page.

## Debugging

The first step of the diagnosis is to turn redirects off. In Requests, `allow_redirects=False` hands you every 3xx response as it is. The script below prints the chain step by step, shows incoming cookies and stops when the same address is about to be requested a third time:

```python
from collections import Counter
from urllib.parse import urljoin

import requests

PROXY = "http://user:pass@pr.proxynet.io:8000"

def print_chain(url, limit=10):
    s = requests.Session()
    s.proxies = {"http": PROXY, "https": PROXY}
    counter = Counter()
    for step in range(1, limit + 1):
        r = s.get(url, allow_redirects=False, timeout=15)
        print(step, r.status_code, url)
        if "Set-Cookie" in r.headers:
            print("   Set-Cookie:", r.headers["Set-Cookie"])
        location = r.headers.get("Location")
        if not location:
            return r
        counter[url] += 1
        url = urljoin(url, location)  # resolve a relative Location
        print("   Location:", location, "->", url)
        if counter[url] >= 2:
            print("   LOOP:", url, "requested a third time")
            return r
    print("   limit exceeded")

print_chain("https://site.example/account")
```

In the IP-bound session test with a rotating proxy, the output looked like this (local address prefixes and the resolved addresses after `->` are shortened):

```text
1 302 /ipbound/account
   Location: /ipbound/consent
2 302 /ipbound/consent
   Set-Cookie: sid=0d002b1d; Path=/
   Location: /ipbound/account
3 302 /ipbound/account
   Location: /ipbound/consent
4 302 /ipbound/consent
   Set-Cookie: sid=af30750a; Path=/
   Location: /ipbound/account
   LOOP: /ipbound/account requested a third time
```

Every round brings a new `sid` even though the cookie was sent. That is the trace of an IP-bound session. With a fixed IP, the same script got a 200 at step three.

For a diagnosis without code, curl is enough. `-v` prints the headers, `--max-redirs` cuts the chain short, and `grep` filters the lines you need:

```bash
curl -sv -o /dev/null -L --max-redirs 5 \
  -x http://user:pass@pr.proxynet.io:8000 \
  https://site.example/account 2>&1 \
  | grep -E '^< (HTTP|Location|Set-Cookie)'
```

Read the output with this table:

| What you see in the chain | Cause | Fix |
|---|---|---|
| New `Set-Cookie` every round, no `Cookie` in the request | Cookie not stored | `Session`, in curl `-c` and `-b` |
| Cookie is sent, a new `Set-Cookie` still arrives | Session bound to IP, IP changes | Sticky session |
| Bouncing between country paths, intermittent | Exit IP country changes | Fixed IP, same country |
| Two hosts alternate, cookie on one host | Host-bound cookie | Report to the site owner |
| `http` ↔ `https` or `www` ↔ bare domain | Conflicting rules on the site | Report to the site owner |

Lower the limit instead of raising it. With `Session.max_redirects = 5`, Requests reports the loop after 5 steps instead of 30. In our test the error was `Exceeded 5 redirects.`

## How we tested

We ran the tests on December 1, 2026 on Windows 11. We used Python 3.13.17, Requests 2.34.2, urllib3 2.6.3, HTTPX 0.28.1, Node 24.22.2 and curl 8.22.0. The target was a local site we wrote with Python `http.server`. It had four setups: a cookie gate, an IP-bound session, a country-based redirect and a cookie across two hosts. In front of it we put two local HTTP proxies. One switched the source address between `127.0.0.2` and `127.0.0.3` on every request, the other kept it fixed. The targets were plain HTTP, so the `CONNECT` tunnel was outside this test. In the examples we replaced the local addresses with `pr.proxynet.io:8000` and `site.example`.

## The bottom line

When you see a loop, first turn redirects off and read the chain. If the cookie is not stored, open a jar. If a new cookie arrives every round, fix the IP. Above all, do not try to get past a loop by raising the limit. If your flow needs a stable exit, [Residential Proxy](https://proxynet.io/residential-proxy) stays on the same IP with a sticky session.

## Sources

- [RFC 9110, §15.4 Redirection 3xx and §10.2.2 Location: rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9110.html#name-redirection-3xx)
- [Fetch Standard, HTTP-redirect fetch: fetch.spec.whatwg.org](https://fetch.spec.whatwg.org/#http-redirect-fetch)
- [curl man page, `-L`, `--max-redirs`, `-b` and `-c`: curl.se](https://curl.se/docs/manpage.html)
- [Requests documentation, Quickstart, Redirection and History: requests.readthedocs.io](https://requests.readthedocs.io/en/latest/user/quickstart/#redirection-and-history)

## Frequently asked questions

### Why does ERR_TOO_MANY_REDIRECTS appear when the proxy is on?

There are two likely causes: the cookie is not stored, or your IP address changes in the middle of the chain. If a rotating proxy gives a new IP on every request, an IP-bound session or a country redirect sends you back to the gate. If the page opens with the proxy off, switch to a sticky session. If it does not open without the proxy either, the problem lies in the site's own rules. In that case, try clearing the site's cookies first.

### How do I fix the Requests TooManyRedirects error?

Print the chain step by step with `allow_redirects=False`. First check whether a new `Set-Cookie` arrives every round. If it does and the request carries no cookie, use `requests.Session`. If the cookie is sent and a new one still arrives, the exit IP is changing, so switch to a sticky session. Put the same proxy under both the `http` and `https` keys of the `proxies` dict.

### Does raising the redirect limit help?

No. A loop does not end on its own, and the limit only decides when the error arrives. Setting 100 instead of 30 in Requests gives the same error later and with more traffic. Do the opposite: during diagnosis, lower `Session.max_redirects` to a small number such as 5. In curl, `--max-redirs 5` does the same job and keeps the output readable.

### How do I see the redirect chain in curl?

Use `-v` together with `-L`. At every step curl prints the status line and the `Location` and `Set-Cookie` headers with a `<` prefix. `--max-redirs 5` keeps the chain short, and `grep -E '^< (HTTP|Location|Set-Cookie)'` drops the noise. curl does not store cookies unless its cookie engine is on. Test cookie-based flows by passing the same file to `-c` and `-b`.

### Why does the loop happen only sometimes?

Because exit IPs arrive in a different order on every run. On a site that redirects by country, the chain ends if the IP stays in the same country. If the country changes between steps, the pages send you to each other. In our test the same code got a 200 in one run and looped in another. If you see an intermittent loop, use a fixed IP from the same country as the requested page for the whole flow.

### Can a rotating proxy open a page that requires login?

Yes, if the login flow runs on a sticky session. In a mode where the IP changes on every request, an IP-bound session cookie is rejected and you land back on the login page. Complete the flow with one session ID on a fixed IP for 1-60 minutes. Use rotation in a separate session to collect independent pages. Only act on your own account and within the site's terms.
