Fixing Redirect Loops
Understanding Redirect Loops
A redirect loop (ERR_TOO_MANY_REDIRECTS) occurs when the browser is endlessly bounced between URLs. This typically happens due to conflicting redirect rules between WordPress, OLS, and Cloudflare.
Most Common Cause: Cloudflare Flexible SSL
If Cloudflare’s SSL mode is set to Flexible, Cloudflare connects to your server over HTTP. But WordPress may force HTTPS, creating a loop:
- Browser requests
https://example.com(via Cloudflare) - Cloudflare connects to your server on HTTP (port 80)
- WordPress detects non-HTTPS and redirects to
https://example.com - Repeat forever
Fix: Set Cloudflare SSL mode to Full or Full (Strict). Your BlitzPress server has a valid SSL certificate.
WWW vs Non-WWW Mismatch
If WordPress is set to https://www.example.com but your OLS rewrite redirects www to non-www (or vice versa), you get a loop. Ensure consistency:
# Check WordPress settings
sudo wp option get siteurl --path=/home/DOMAIN/public_html --allow-root
sudo wp option get home --path=/home/DOMAIN/public_html --allow-root
Both should match your canonical URL (either with or without www, not mixed).
Fix via WP-CLI (When wp-admin is Inaccessible)
sudo wp option update siteurl "https://example.com" --path=/home/DOMAIN/public_html --allow-root
sudo wp option update home "https://example.com" --path=/home/DOMAIN/public_html --allow-root
OLS Rewrite Rules
Check for conflicting rewrites in your vhost config:
cat /usr/local/lsws/conf/vhosts/DOMAIN/vhconf.conf
Look for redirect rules that might conflict with WordPress or Cloudflare redirects.
Plugin Redirect Conflicts
Some plugins (Really Simple SSL, Yoast, Redirection) add their own redirect rules. Disable all plugins to test:
sudo wp plugin deactivate --all --path=/home/DOMAIN/public_html --allow-root
If the loop stops, re-enable plugins one at a time to find the culprit.
Clear Browser State
After fixing the issue, clear your browser cache or test in an incognito window. Browsers aggressively cache 301 redirects.