/cgi-bin/php5.cgi/myfolder/index.php and now the re-writes whip the index.php off the end of that, and all hell breaks loose.
Either exclude the path via a rule above all or switch the whole thing off by placing a .htaccess into your cgi-bin with RewriteEngine off. That would prevent runtime execution of mod_rewrite as well (excluding won't).
# Internally rewrite requests for "index.html" or "/" to "index.php"
Since you're redirecting index.html requests... instead of rewriting internal lookups for index.html like those caused by mod_dir (DirectoryIndex) you may want to adjust DirectoryIndex to DirectoryIndex index.php