2010-07-20 Apache Rewrite Loops

My Apache error.log file for emacswiki.org is full of the following:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ’LimitInternalRecursion’ to increase the limit if necessary. Use ’LogLevel debug’ to get a backtrace.

In addition to that, 0.35% of my access.log entries (263/74905 in the current log file) seem to result in an internal server error – which is exactly what the Apache documentation says:

In order to prevent endless loops of internal redirects issued by per-directory RewriteRules, mod_rewrite aborts the request after reaching a maximum number of such redirects and responds with an 500 Internal Server Error. ¹

¹

I checked the two big .htaccess files (one for cgi-bin, another one for htdocs) and all the RewriteRule entries have the `[L]` or `[last]` flag. ²

²

How can I debug this? This is a shared hosting environment. I cannot use LogLevel. 🙁

Apparently ordinary users are running into the same problem. DrewAdams is reporting that every now and then when he’s saving a page, he gets the internal server error. Saving involves a POST request with a redirecting reply – code 302. This is theoretically non-standard but widely used:

Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. – RFC 2616, section 10.3.3 “302 Found”

Want to take a look?

htdocs/.htaccess

cgi-bin/.htaccess

​#Apache ​#Emacs

Comments

(Please contact me if you want to remove your comment.)

Rewrite works somewhat differently in .htaccess files; see the more recent doc for [Last] at http://httpd.apache.org/docs/trunk/rewrite/flags.html​#flag\ l for some warnings.

http://httpd.apache.org/docs/trunk/rewrite/flags.html​#flag\ l

– Dan Poirier 2010-07-23 00:55 UTC