What Is a Redirect Loop?
How redirect loops happen, common causes like circular .htaccess rules and HTTP/HTTPS conflicts, how to diagnose them, and step-by-step instructions to fix them.
A redirect loop is when URL A redirects to URL B, which redirects back to URL A (or through a longer chain that eventually circles back). The browser follows the redirects in an infinite circle until it gives up and shows an error.
You have seen the error message. In Chrome it says "ERR_TOO_MANY_REDIRECTS." In Firefox it says "The page isn't redirecting properly." In Safari it says "Too many redirects occurred." They all mean the same thing: your server is sending the browser in circles.
How a Redirect Loop Works
The simplest loop is two URLs pointing at each other:
https://example.com/page-a
--> https://example.com/page-b
--> https://example.com/page-a
--> https://example.com/page-b
--> (infinite loop)
But loops can be longer and harder to spot:
/page-a --> /page-b --> /page-c --> /page-d --> /page-a
^
back to start
Browsers typically follow 20 redirects before giving up. Chrome stops at 20. Firefox stops at 20. The user sees nothing but an error page.
Common Causes
1. HTTP/HTTPS Conflict
This is the number one cause of redirect loops in the wild. It happens when one rule forces HTTPS and another rule forces HTTP.
# Rule 1 (in .htaccess): Force HTTPS
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
# Rule 2 (in application or CDN): Force HTTP
# (misconfigured load balancer terminating SSL and redirecting back)
if (protocol == "https") redirect to "http://..."
The server says "go to HTTPS." The load balancer strips SSL and the app sees HTTP, so it says "go to HTTPS." Forever.
Load balancer SSL termination
This is the most insidious cause because the redirect rules look correct in isolation. The loop only happens because the load balancer terminates SSL, making the application think every request is HTTP. Check the X-Forwarded-Proto header.
2. WWW vs Non-WWW Conflict
Similar to the HTTPS issue. One rule redirects to www, another redirects away from it.
# Server config: redirect to www
example.com --> www.example.com
# CDN config: redirect to non-www
www.example.com --> example.com
# Result: infinite loop
3. Circular .htaccess or Nginx Rules
Overlapping rewrite rules that match each other's output:
# Rule 1: Add trailing slash
RewriteRule ^(.+[^/])$ /$1/ [R=301,L]
# Rule 2: Remove trailing slash
RewriteRule ^(.+)/$ /$1 [R=301,L]
# Result: /page --> /page/ --> /page --> /page/ --> ...
4. CMS Plugin Conflicts
WordPress is notorious for this. A security plugin forces HTTPS while a caching plugin or CDN plugin has its own redirect rules. Two plugins fighting over the same redirect creates a loop.
5. CDN and Origin Server Disagreement
Your CDN (Cloudflare, Fastly, CloudFront) has redirect rules. Your origin server also has redirect rules. If they disagree about where traffic should go, loops happen.
CDN rule: http://example.com --> https://example.com (good)
Origin rule: Force redirect to http://example.com (bad)
CDN: "Go to HTTPS"
Origin: "Go to HTTP"
CDN: "Go to HTTPS"
(loop)
Trace your redirect chains
Find redirect loops, broken chains, and unnecessary hops instantly.
How to Diagnose a Redirect Loop
Step 1: Use curl to See the Chain
curl -v -L --max-redirs 10 https://example.com/problem-page 2>&1 | grep -E "^< HTTP|^< [Ll]ocation"
This shows each hop with its status code and destination. When you see the same URL appear twice, you have found your loop.
Step 2: Check Each Layer Independently
The loop usually involves two different systems. Check each one:
# Check what the origin server does (bypass CDN)
curl -I -H "Host: example.com" https://your-origin-ip/problem-page
# Check what the CDN does
curl -I https://example.com/problem-page --max-redirs 0
Step 3: Inspect Headers
Look for X-Forwarded-Proto, X-Forwarded-For, and Via headers. These reveal whether a proxy or load balancer is involved in the loop.
Step 4: Check All Redirect Sources
Redirects can come from multiple places. Check all of them:
Server config
.htaccess files
Application code
CDN rules
Load balancer
CMS plugins
DNS-level redirects
How to Fix Common Loops
Fix: HTTP/HTTPS Loop with Load Balancer
Trust the X-Forwarded-Proto header from your load balancer instead of checking the connection protocol directly:
# Nginx - check the forwarded protocol, not the connection
map $http_x_forwarded_proto $redirect_to_https {
default 0;
http 1;
}
server {
if ($redirect_to_https) {
return 301 https://$host$request_uri;
}
}
Fix: WWW vs Non-WWW Loop
Pick one canonical version and configure it in exactly one place. Remove all conflicting rules.
# Pick non-www as canonical. Configure in ONE place only.
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
Fix: Trailing Slash Loop
Choose one convention and apply it consistently:
# Add trailing slash (pick ONE approach)
rewrite ^([^.]*[^/])$ $1/ permanent;
Fix: WordPress Plugin Loop
- Deactivate all plugins via the database or file rename
- Reactivate one at a time
- Test for the loop after each activation
- The plugin that triggers the loop is your culprit
Quick WordPress fix
Before debugging plugins, try clearing your WordPress cache, browser cache, and CDN cache. Many "redirect loops" are actually cached redirects from a previously misconfigured state that has already been fixed.
Prevention
- Configure redirects in one place. Do not split redirect logic between your server config, .htaccess, application code, and CDN. Pick one authoritative source.
- Test after every change. After modifying any redirect rule, immediately test the affected URLs.
- Monitor continuously. Redirect loops can appear when a third party (CDN, hosting provider, CMS update) changes their behavior. Ongoing monitoring catches these before users do.
Related Articles
A redirect loop is two systems arguing about where traffic should go. The fix is always the same: make one of them stop.
Never miss a broken redirect
Trace redirect chains and detect issues before they affect your users and SEO. Free instant tracing.