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?

  • You can't use two %{} parameters in a single RewriteCond.. use REQUEST_URI for your rule above – yoavmatchulsky Jan 21 '12 at 13:24
  • 2
    this is not true, you can use multiple %{} parameters, this will look for the regex in the concatenated string – Yaron Uliel Jan 21 '12 at 13:28
  • 1
    @yoavmatchulsky בכיף :) – Yaron Uliel Jan 21 '12 at 13:39

Change your code with this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
  • That will check if the URL doesn't exists.. that's not what he asked for.. – yoavmatchulsky Jan 21 '12 at 13:25
  • 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 – Yaron Uliel Jan 21 '12 at 13:29
  • @yoavmatchulsky: That's not correct, please read Apache docs again. It will only check if requested file exists then don't apply the rule. – anubhava Jan 21 '12 at 15:07
  • @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. – anubhava Jan 21 '12 at 15:17
  • @BartZweers: Can you please let me know if you tried this answer? If yes then kindly inform if it resolved your 500 error or not? btw I have tested this answer on my Apache and it worked fine. – anubhava Jan 21 '12 at 15:19

You need to exclude the target you are redirecting too:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js)$
RewriteCond $1 !=index.php
RewriteRule ^(.*)  index.php
  • This seems quite logical, however it does not solve the problem. Thanks for your help anyway. – Bart Zweers Jan 21 '12 at 13:34

Try the following to prevent internal redirects

RewriteEngine On
#removed %{DOCUMENT_ROOT} as it is unnecessary
RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js)$ [NC]
#Prevent internal redirects
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*)  index.php [L]
  • 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 – Bart Zweers Jan 21 '12 at 14:49
  • @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. – Ulrich Palha Jan 21 '12 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy