CakePHP: Error 500 Too Many Redirects

Another error I ran into was this error:

Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'Limit InternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

It took a lot of looking, and I found out that it was an error in my .htaccess file. However, there are three major .htaccess files in a typical CakePHP application

  1. The Cake Folder .htaccess
  2. The App Folder .htaccess
  3. The Webroot Folder .htaccess

It’s hard to figure out which .htaccess file you have to edit, but my first guess was the webroot folder.

I have setup my directory structure using the alternative setup described later in the CakePHP manual:

  • webroot: This is in /var/www/testing (where testing is the virtual directory of my application (testing.blah.com)
  • app: This is in /home/eric/cake/testingapp
  • cake: This is in /home/eric/cake/cake_1.1.12.4205

The setup seemed to be working, and my normal front page appeared, but if I went to another controller (i.e. testing.blah.com/user/login) I would get the Error 500 message and the Apache error log file said I had done too many redirects in the application.

The solution is extremely easy, but it was very hard to find! But I found it on the IRC logs here: http://irc.cakephp.org/cakephp/viewlog/2007-01-11#2234 courtesy of poLK:

Edit the .htaccess file in webroot (for me that was in /var/html/testing/.htaccess) and add the line “RewriteBase /” to the file, so my .htaccess file now looks like this:

RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

It's a simple change, but took me about an hour or two of research, Google and Groups searching to figure out.

11 thoughts on “CakePHP: Error 500 Too Many Redirects”

  1. It took me 3 hours to end up looking on google and finding this post.

    Thanks a mill !!!
    I think it should be something written on the Cake manual

  2. Altought rewritebase wasn’t my problem, I got to this error just because app and app/webroot htaccess were missing due to compressing program not adding them – thanks, helped me fix that.

  3. Thanks for the tip Tomas. You do have to watch out for losing the .htaccess files, especially when you’re on a Unix/Linux system since they’re hidden. :P

  4. THANK YOU!!!

    It didn’t save me a few hours, but it really helped me from throwing my computer out the window!

    They should have written this in the cake manual where it gives instructions for the advanced install.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>