What to Do When Your Backend Betrays You with ERR_TOO_MANY_REDIRECTS!


#1

You’ve reached this page because you saw an error that looked something like this ERR_TOO_MANY_REDIRECTS, which means you might be stuck in a redirect loop.

What is a redirect loop?
A redirect loop is a redirect that points to itself, causing an endless loop. This can happen with a 301 or 302 HTTP response. In this response there is a location header that directs the browser where to go. If the location header matches the request location you can get stuck in a loop. This doesn’t happen often but when it does it can be frustrating to say the least.

Using Custom VCL
I am going to demonstrate a fix using custom VCL. If you don’t have Custom VCL enabled follow these instructions. You can add a condition that looks something like this:

 if ( beresp.status == 302 && beresp.http.location == "< URL > " ) {
  
        
      # PASS home page 302 redirects
      set beresp.ttl = 0s;
      set beresp.grace = 0s;
      return(pass);
    
 
 
 
  }

This action is taken in order to pass that request to origin rather than falling back into the loop.

Using Cache Settings
You can create a condition that looks like the above using this help doc.

Remember Logging is important!
This is an error that only shows up occasionally. With logging enabled you will be able to catch this error before it becomes troublesome. Check out our tutorial on setting up a logging service here.