I am trying to rewrite URLS so that /foo -> index.php.
index.php is powered by codeigniter 3. bar.php is a stand alone php file.
This is a snipped from my .htac
Take a look at https://gist.github.com/keithmorris/3023560
This includes a fairly standard htaccess file that I use on all my projects. You then use the CI routing functionality to define where different bits go.
Bear in mind with CI you can pass additional elements in a url such as example.com/foo1/foo2/foo3/query1/query2.