WordPress

Too many redirects on WordPress: finding the loop

A redirect loop is two rules that disagree about the right address, each sending the browser to the other. One command shows you the chain, and the chain shows you which two rules are arguing. Here are the five usual pairs and how to settle each.

You switch the site to HTTPS, or put it behind Cloudflare, and every visit now ends in ERR_TOO_MANY_REDIRECTS: "example.com redirected you too many times". Firefox calls it "The page isn't redirecting properly". Nothing in WordPress is broken as such. Two rules disagree about the right address, and the browser is caught between them.

What does "too many redirects" mean?

It means the browser followed a redirect, then another, then another, and gave up after about twenty without ever receiving a page. Each redirect is a rule somewhere saying "not here, go there". A loop happens when two rules point at each other: one sends http to https while another sends it back, or one adds www while another removes it.

The rules can live in several places at once: your CDN or proxy, the web server configuration or .htaccess, WordPress's own address settings, and redirect plugins. The fix is always to find the two that disagree and remove one.

How do you see the loop?

Ask for the page with curl, follow a limited number of redirects, and print only the status lines and the addresses:

curl -sIL --max-redirs 6 https://example.com | grep -iE '^(HTTP|location)'

The output is the chain the browser followed. A loop shows up as the same two addresses alternating, such as https://example.com/ answering with location: https://example.com/, or example.com and www.example.com taking turns. The browser's Network tab shows the same thing if you tick "Preserve log" first. Headers such as server: cloudflare or x-redirect-by: WordPress often tell you which layer sent each step.

Which rules usually disagree?

1. HTTPS behind a proxy that talks plain HTTP to your server. This is the classic one. Cloudflare set to Flexible SSL, or a load balancer that ends HTTPS itself, forwards each request to your server over plain http. WordPress, configured for an https address, or an .htaccess rule that forces HTTPS, sees an insecure request and redirects to https. The redirect goes back through the proxy, which forwards over http again, forever.

Diagram: the most common WordPress redirect loop. A visitor requests https://example.com. Cloudflare, set to Flexible SSL, forwards the request to the origin server over plain http. WordPress or an .htaccess rule sees an http request and redirects to https. The browser follows the redirect back to Cloudflare, which again forwards over http, and the cycle repeats until the browser stops with ERR_TOO_MANY_REDIRECTS. The fix is Full (strict) SSL with a certificate on the origin, or telling WordPress the original request was HTTPS through the X-Forwarded-Proto header.
HTTPS behind a proxy that talks plain HTTP to your server: the classic loop.

The proper fix is HTTPS all the way: install a certificate on the server and set Cloudflare's SSL mode to Full (strict). Where the proxy must talk plain HTTP, tell WordPress that the original request was secure. The WordPress documentation gives this for wp-config.php, above the line that says to stop editing:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
    $_SERVER['HTTPS'] = 'on';
}

Only use it behind a proxy you control that sets that header, because any visitor can send it otherwise.

2. www and non-www disagree. The host or the server configuration sends visitors to www.example.com, while WordPress is set to example.com and sends them back. Pick one address, set WordPress to it, and make every other rule agree.

3. Redirect rules point at each other. A redirect plugin with an old entry from page A to page B, and a newer one from B back to A. Check the plugin's list of redirects for the addresses in your chain.

4. Only the login page loops. You log in, land on wp-login.php again, and repeat. That is usually cookies rather than addresses: the site is reached on a different host or scheme from the one WordPress has stored, so the login cookie is set for one address and the dashboard looks for it on another. The same HTTPS-behind-a-proxy problem from case 1 often causes this as well.

5. A cached redirect. A CDN or the browser is replaying a redirect from an older configuration. Purge the CDN cache after changing redirect rules, and test in a private window.

How do you fix it without the dashboard?

A loop usually locks you out of wp-admin too, so fix the settings from outside. Two constants in wp-config.php override the WordPress Address and Site Address stored in the database:

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

With shell access, WP-CLI reads and updates the stored values directly, and its search and replace handles the old addresses inside your content, including serialized data, which a raw database query would break. Run it with --dry-run first:

wp option get home
wp option get siteurl
wp search-replace 'http://example.com' 'https://example.com' --dry-run

Once the chain ends in a single 200, check the site from outside your network, as described in the first five minutes, since your own browser may still be holding an old redirect.

Found something wrong in here? Tell me.

Checking API...
Checking AI Gateway...
Check status
⚠️ Setup Required