.htaccess mod_rewrite 500 internal server error due to too many internal redirects from LimitInternalRecursion

8,233

Change your code with this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Share:
8,233

Related videos on Youtube

Stephen Ostermiller
Author by

Stephen Ostermiller

Updated on September 18, 2022

Comments

  • Stephen Ostermiller
    Stephen Ostermiller over 1 year

    Whenever I place my .htaccess file in my web directory I receive a 500 internal server error and within the error.log file specifying:

    [Sat Jan 21 13:46:07 2012] [error] [client xx.xx.xxx.xx] 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.
    

    My .htaccess file:

    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js)$
    RewriteRule ^(.*)  index.php
    

    I have tried enabling Options +FollowSymLinks but this has been fruitless.

    Everything works locally. Any pointers as to what I could be doing wrong?

    • Admin
      Admin about 12 years
      You can't use two %{} parameters in a single RewriteCond.. use REQUEST_URI for your rule above
    • Admin
      Admin about 12 years
      this is not true, you can use multiple %{} parameters, this will look for the regex in the concatenated string
    • Admin
      Admin about 12 years
      @yoavmatchulsky בכיף :)
  • Admin
    Admin about 12 years
    That will check if the URL doesn't exists.. that's not what he asked for..
  • Admin
    Admin about 12 years
    also, if you want to check the -f flag, you need to check it against the full path of the file, just the REQUEST_FILENAME will always return false
  • Admin
    Admin about 12 years
    This seems quite logical, however it does not solve the problem. Thanks for your help anyway.
  • Admin
    Admin about 12 years
    The error log now says [Sat Jan 21 15:40:40 2012] [alert] [client xx.xx.xxx.xx] /home/sites/xxx/subdomains/xxx/.htaccess: RewriteCond: bad flag delimiters
  • anubhava
    anubhava about 12 years
    @yoavmatchulsky: That's not correct, please read Apache docs again. It will only check if requested file exists then don't apply the rule.
  • Admin
    Admin about 12 years
    @BartZweers I had an extra space in my expression, but fixed it above. Try the edited version. Also, confirm that you do not have any other rules in this, or other .htaccess files.
  • anubhava
    anubhava about 12 years
    @YaronUliel: Go and read some Apache documentation before reaching to conclusion like this. REQUEST_FILENAME is indeed the full path of the requested file not just the base file name. And even though OP showed images in his example eventually that rule will be needed to avoid redirection for all static files like images, css, js etc. That's why it is important to avoid it like this.
  • Admin
    Admin about 12 years
    @anubhava tnx for your reply - I confused between REQUEST_FILENAME, and REQUEST_URI. my mistake
  • Admin
    Admin about 12 years
    @anubhava I removed the first line. It works perfectly now. Thanks a lot!
  • anubhava
    anubhava about 12 years
    You're welcome, glad that it worked out. I think this is my accepted answer with a negative vote :) ... not sure why the down-voter did so though.