Subtle diagonal pinstripe pattern in light grey and cream, giving an impression of printed editorial paper

Fix too many redirects in WordPress behind a load balancer

When WordPress returns a “Too Many Redirects” or “ERR_TOO_MANY_REDIRECTS” error, the browser has followed a chain of redirects without reaching the page. Behind a load balancer, a common loop begins when TLS ends at the proxy, the proxy forwards HTTP to WordPress, and the application treats the request as insecure. WordPress redirects to the same public HTTPS address, sends the browser back to the proxy, and repeats the cycle.

The fault can also come from a canonical host mismatch, a stale site URL, a redirect plugin, or a health check that rejects the origin’s valid redirect. Start with the first Location header rather than changing settings at random. This process suits single-site WordPress, WooCommerce, and managed Australian deployments using AWS, Azure, Google Cloud, or an Australian host with a CDN.

Trace the redirect chain

Use a cookie-free request so authentication rules do not distort the result. These commands show the first response and then follow the chain:

curl -I https://example.com.au/
curl -sSIL --max-redirs 5 https://example.com.au/
First response Likely fault Evidence to collect Corrective action
HTTPS redirects to the same HTTPS URL The origin does not recognise public HTTPS Compare the proxy request with the origin request Forward and trust the correct protocol header
HTTPS redirects to another hostname WordPress URL or canonical host differs Check home, siteurl, Host, and X-Forwarded-Host Use one canonical hostname everywhere
Only administrators or logged-in users loop Security, login, or SSL plugin Compare cookie-free and authenticated requests Correct or isolate the plugin rule
Some requests return 503 The health check marks the target as unhealthy Review target health and the check path Use the canonical host and a reliable 200 response

The Location value is the key evidence. If the first response sends an HTTPS URL back to the same HTTPS URL, the proxy-to-origin scheme is probably wrong. If it moves to a different hostname, compare WordPress URLs with the Host header. Repeat the check on /wp-admin/, /wp-login.php, and a WooCommerce checkout route because a plugin can affect only part of the site.

Make WordPress recognise forwarded HTTPS

WordPress normally decides whether a request is secure from server values such as HTTPS and SERVER_PORT. A load balancer should send the original scheme in X-Forwarded-Proto; WordPress does not reliably interpret every proxy arrangement by itself. If the balancer forwards to port 80, tell WordPress that the client reached the proxy over HTTPS.

Place this in wp-config.php before the “stop editing” line, adapting it to the header format used by your chain:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
    $forwarded_proto = strtolower(
        trim( explode( ',', $_SERVER['HTTP_X_FORWARDED_PROTO'] )[0] )
    );

    if ( in_array( $forwarded_proto, array( 'http', 'https' ), true ) ) {
        $_SERVER['HTTPS']       = ( 'https' === $forwarded_proto ) ? 'on' : 'off';
        $_SERVER['SERVER_PORT'] = ( 'https' === $forwarded_proto ) ? '443' : '80';
    }
}

Apply the mapping only when the request came through a trusted proxy. A client can forge a forwarded header, so restrict the origin with cloud security groups or a firewall and make the load balancer overwrite the header rather than preserve an arbitrary client value. This follows the same defence-in-depth approach promoted by the Australian Cyber Security Centre.

Cloud providers differ in their defaults. AWS Application Load Balancers and Google Cloud HTTP(S) load balancers normally add X-Forwarded-Proto, but a target-group setting, CDN, or custom reverse proxy can change the result. Check the request received by PHP instead of assuming the console setting worked. A temporary, access-controlled diagnostic page can display the relevant server values; remove it immediately after testing.

Configure the proxy and forwarded headers

At the proxy, preserve the canonical Host, forward the original scheme, and identify the public port. For a public HTTPS listener, the target group may use HTTP on port 80 because TLS has already been decrypted, provided the forwarded scheme remains https. Do not replace the public host with an internal target name unless WordPress is intentionally configured for that name.

If Nginx is the public TLS proxy, the equivalent forwarding directives are:

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

When Nginx sits behind another load balancer, do not blindly set $scheme to https: in that position $scheme may be http. Take the value from the trusted incoming header, or keep protocol handling at the outermost proxy. Likewise, treat X-Forwarded-Host as untrusted input; accepting it blindly can create an open redirect to an attacker-controlled domain.

Many Australian managed hosts place a CDN in front of the application balancer, adding another proxy layer. Decide which component owns the HTTP-to-HTTPS redirect, then make every later layer preserve that decision. With Cloudflare, use Full (strict) TLS rather than Flexible mode and verify the forwarded scheme after Cloudflare, the balancer, and any caching layer. For teams using AWS in Sydney (ap-southeast-2) or Google Cloud in Melbourne (australia-southeast1), the same header contract must work in every region and failover pool.

Align WordPress URLs and redirect rules

Check the values WordPress actually uses. On a single site, WP-CLI can inspect and update them:

wp --path=/var/www/html option get home
wp --path=/var/www/html option get siteurl
wp --path=/var/www/html option update home 'https://example.com.au'
wp --path=/var/www/html option update siteurl 'https://example.com.au'

Back up the database first, and update the database and wp-config.php rather than leaving conflicting definitions in place. The constants override stored options:

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

Australian businesses often use a .com.au domain for local trust while a .com domain supports broader campaigns. Pick one hostname as the canonical WordPress address, keep home and siteurl identical apart from any deliberate subdirectory, and redirect the other hostname at the edge. Mixed values are a frequent source of redirect_canonical loops, especially when the load balancer passes www but the application expects the apex domain.

Review .htaccess, Nginx rules, force-SSL plugins, security plugins, and maintenance modes. The common .htaccess condition checks the scheme seen by Apache; behind an HTTP origin connection that value may remain off, causing another redirect to HTTPS. If the proxy already upgrades the request, remove the duplicate application rule or make it proxy-aware. In wp-config.php, FORCE_SSL_ADMIN affects administration screens only and does not correct the public URL or frontend loop. For multisite, inspect network settings as well as each site.

Separate application, cache, and health-check faults

If the proxy and WordPress URLs now match, isolate application redirects on a staging clone. Plugins for SSL enforcement, canonical domains, login security, firewalls, and maintenance can each create a redirect. Compare curl output with a logged-out browser and an administrator session; a loop limited to one role points to an access rule. Deactivate one suspect plugin at a time in the clone, then reproduce the redirect with the same host, scheme, and cookies.

Purging the CDN, reverse-proxy cache, host page cache, and WordPress cache can remove an old cached 301 or 302. Test in a private window and restart the browser after changes. WooCommerce also stores sessions and transients, but clearing those should follow a normal maintenance procedure rather than a blind reset on a live store. Inspecting cache and application logs around the exact request time will show whether the response was generated by WordPress or an edge service.

Check load-balancer target health next. A health check that requires HTTP 200 can mark a healthy WordPress target as failed when the origin redirects to HTTPS because many managed health checks do not follow redirects. Use an unauthenticated static health file that returns 200 with the canonical host, or configure the provider to accept the intended redirect. Do not point the check at /wp-login.php: login plugins, rate limits, cookies, and security redirects can make it unreliable.

Verify the fix and establish safeguards

Apply one change at a time and keep a record of the previous value. After each change, repeat the header-only and followed requests, then test the homepage, a page, media, REST API, login, admin, and checkout. The expected result is a direct 200 response or one deliberate redirect, such as an apex-to-www redirect, never an endless chain. Review both the load balancer and origin logs for the request ID while testing.

For an Australian store, a redirect loop during peak trade is a fair way to lose both orders and search visibility. Re-test after load balancer, CDN, DNS, security-rule, and plugin changes. A healthy site answers the first public HTTPS request directly, while any remaining redirect has one clear purpose and a stable destination.