NNLocke NNLocke - 10 months ago 51
Apache Configuration Question

10 internal redirects - can this limit be raised?

I have a client running into some 500 errors when using a CDN. These errors indicate that there are too many internal redirects, and our research confirms that. The client does not want to adjust their internal redirects, and wants to address this problem in another way.

Based on my research so far, this seems like a hard cap which is not specific to any one type of web server, and is in place to avoid endless loops. That being said, is there any way to raise this limit - for instance to 20 instead of 10?


  1. Browser >>9 redirects>> Origin 200 page (9 redirects total)

  2. Browser >>9 redirects>> Origin gives custom 404 page (+1 redirect for custom 404 - 10 redirects total)

  3. Browser >> CDN (+1 redirect from custom rule) >>9 redirects>> Origin 200 page (10 redirects total)

  4. Browser >> CDN (+1 redirect from custom rule) >>9 redirects>> Origin gives custom 404 page (+1 redirect for custom 404 - 11 redirects total)

Only example 4 gives a 500 error. Without adjusting the redirect configuration or removing the CDN, is there any way to get around this? (Unfortunately, I cannot provide htaccess for more info on the redirects, my apologies).

Answer Source

Unfortunately it is the HTTP client who decides how many redirects it is willing to follow. The limitation you see stems from a recommendation originally given in RFC 2068, sec 10.3 and quoted again in RFC 7231, sec 6.4:

An earlier version of this specification recommended a maximum of five redirections [...] Content developers need to be aware that some clients might implement such a fixed limitation.

A rough estimate on how many redirects are going to hit the limit for browsers can be found in this answer. Most browsers allow to configure this limit (e.g. Firefox is exposing the network.http.redirection-limit setting).

Webservers then are a different matter: It appears Apache had the MaxRedirects option for the RewriteOptions directive between v2.0.45 and 2.1. The LimitInternalRecursion setting seems to have taken over for this. I've been unable to find an equivalent setting for nginx.

As a final note: If you are really seeing this many internal redirects (i.e. redirects that are only performed within the rewrite engine and do not lead to real HTTP redirects immediately), this may be a strong indicator to revise your rewrite rules.