Management Guides Troubleshooting

WordPress ERR_TOO_MANY_REDIRECTS: Find the Redirect Loop and Fix It

ERR_TOO_MANY_REDIRECTS on WordPress means two layers disagree about the site's address. How to see the loop with curl and fix it in Cloudflare, nginx, wp-config.php or the database.

Chrome shows "This page isn't working. example.com redirected you too many times. ERR_TOO_MANY_REDIRECTS". Firefox shows "The page isn't redirecting properly". Both mean the same thing: the browser was sent from one address to another and back again until it gave up.

A redirect loop on WordPress almost always comes from two layers that disagree about the correct address of the site: HTTP or HTTPS, with or without www. The layers are the CDN or proxy, nginx, WordPress itself and its plugins. The fix is to find which two are arguing, and make them agree.

The commands below follow the official WP-CLI, WordPress and Cloudflare documentation. They were not run on a test server for this article.

See the loop with curl

A browser hides the chain of redirects and caches parts of it. curl shows each hop:

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

-I asks for headers only, -L follows redirects. Read the location lines. They show the pattern, for example https://example.com/ repeated (HTTPS to HTTPS), or www and non-www alternating.

If the site is behind Cloudflare or another proxy, ask the origin server directly as well. --resolve makes curl connect to your server's IP address while still sending the right host name:

curl -sI --resolve example.com:443:YOUR_SERVER_IP https://example.com/
curl -sI --resolve example.com:80:YOUR_SERVER_IP http://example.com/

If the origin answers 200 over HTTPS when asked directly but loops through the proxy, the cause is in the proxy settings.

Causes at a glance

What you seeLikely causeWhere to look
Loop only through Cloudflare, location is the same HTTPS URL each timeSSL mode "Flexible" and an origin that redirects HTTP to HTTPSCloudflare SSL/TLS settings
Same pattern behind a load balancer or another proxyWordPress does not know the visitor used HTTPSwp-config.php, proxy headers
www and non-www alternatehome/siteurl disagree with the nginx redirectwp option get home, nginx server blocks
Started after a migration or domain changeOld address still in the database or in constantswp search-replace --dry-run
Front end works, only /wp-admin or the login page loopsLogin cookies or FORCE_SSL_ADMINBrowser cookies, wp-config.php, page cache rules

Cloudflare set to "Flexible"

In Flexible mode Cloudflare talks to your server over plain HTTP, even when the visitor used HTTPS. If nginx or WordPress redirects every HTTP request to HTTPS, Cloudflare receives that redirect, passes it to the browser, the browser asks for HTTPS again, and Cloudflare again fetches it over HTTP. This is the most common cause on a VPS that already has its own certificate.

The fix is on the Cloudflare side: in the SSL/TLS settings change the encryption mode to Full (strict). That mode needs a valid certificate on the origin, such as one from Let's Encrypt or a Cloudflare Origin CA certificate. Cloudflare's redirect troubleshooting page lists the other combinations, including the reverse case where the origin redirects HTTPS back to HTTP.

Verify with the first curl command. The chain should end in HTTP/2 200.

A proxy terminates TLS and WordPress does not know

If a load balancer, a container proxy or a second nginx handles HTTPS and forwards plain HTTP to WordPress, WordPress believes the request was insecure and redirects to HTTPS. The request was already HTTPS, so the loop never ends.

The proxy has to pass the original scheme in a header. In an nginx proxy that is:

proxy_set_header X-Forwarded-Proto $scheme;

WordPress has to read it. The WordPress HTTPS documentation gives this snippet for wp-config.php. Place it above the line that loads wp-settings.php:

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

Only use it when the server can be reached through the proxy alone. A visitor who can reach the origin directly can send that header too. Verify by repeating the curl command through the proxy.

This does not apply when nginx on the same server holds the certificate and passes requests to PHP-FPM. In that setup the standard fastcgi_params file already tells PHP whether the request used HTTPS.

siteurl and home do not match what the server redirects to

WordPress stores its address in two options: home (the address visitors use) and siteurl (where the core files are). WordPress redirects visitors to the host in home. If nginx redirects www.example.com to example.com while home says https://www.example.com, each sends the visitor back to the other.

cd /var/www/example.com
wp option get home
wp option get siteurl

Both must use the same scheme and host as the one nginx redirects to. Fix them with:

wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'

No trailing slash. If the values come back unchanged, they are fixed by constants in wp-config.php, which override the database:

grep -nE "WP_HOME|WP_SITEURL" wp-config.php
wp config set WP_HOME 'https://example.com'
wp config set WP_SITEURL 'https://example.com'

The constants are also the quickest repair when the admin area is unreachable. Run wp option get home again to confirm, then repeat the curl test. The WP-CLI guide covers installing wp if the command is missing.

The same redirect is done twice

Pick one place for each redirect. HTTP to HTTPS and the choice between www and non-www belong in nginx. A plugin that forces HTTPS or manages redirects on top of that can contradict it. List what nginx does and which plugins are active:

sudo nginx -T 2>/dev/null | grep -nE 'server_name|return 30|rewrite '
wp plugin list --status=active

Deactivate the suspect and test again:

wp plugin deactivate PLUGIN-SLUG
curl -sIL --max-redirs 10 https://example.com/ | grep -iE '^(HTTP|location)'

In nginx, check that the HTTPS server block does not itself contain a redirect to HTTPS, and that only one server block answers each host name.

After a migration or a domain change

The old address may still be stored in many places in the database. wp search-replace replaces it and handles PHP serialized data correctly, which a plain SQL replace does not. Always look first:

wp search-replace 'http://old.example' 'https://example.com' --skip-columns=guid --dry-run

If the report looks right, take a database backup (wp db export), run the same command without --dry-run, then run wp cache flush. The options are described in the wp search-replace reference. For the full move, see migrating from one VPS to another.

The loop is only on wp-admin or the login page

When the front end loads and only /wp-admin bounces to wp-login.php and back, WordPress is not receiving a valid login cookie. Check these in order:

  • Old cookies. Delete the cookies for the domain, or try a private window. Cookies set for the old scheme or host are a frequent cause after a change.
  • FORCE_SSL_ADMIN behind a proxy. With this constant set to true and no forwarded-protocol snippet, the admin area loops while the front end works. Add the snippet from the proxy section.
  • home and siteurl on different hosts. The cookie is set for one and checked on the other.
  • A page cache that stores login pages. The cache must skip /wp-admin, wp-login.php and logged-in users. See the bypass rules in the nginx FastCGI cache guide.

Multisite

A multisite network keeps the address of each site in its own tables, and the main domain in the DOMAIN_CURRENT_SITE constant in wp-config.php. WP_HOME and WP_SITEURL are not the tool here. List the stored addresses with wp site list --fields=blog_id,url, and add --network to wp search-replace so that every site's tables are included.

Clear cookies and caches last

Browsers remember permanent (301) redirects, so a fixed site can still loop in the browser you tested with. After the curl output is clean:

  • Delete the site's cookies and cached files in the browser, or confirm in a private window.
  • Purge the Cloudflare cache and any page cache on the server.
  • If the site now shows a different error, such as a 502, continue with 502 Bad Gateway on nginx.
Share story:

Continue reading other guides on How VPS.