使用PHP和MySQL重写Mod

I am trying to get a mod rewrite script to work, but for some reason I cannot seem to get things functioning properly. I know that mod_rewrite is working, because if I run the following test it redirects correctly:

RewriteEngine on
RewriteRule ^oranges.html$ apples.html

However, if I try and push all queries to an index file or something to process using php then it does not work:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .? index.php [L]

What I am trying to achieve is to have a database table with two columns, one with an ID and the other with a rewrite URL. So what I mean by this is:

ID | URL
16 | nice-url-1
17 | nice-url-2

So the actual URL is /index.php?id=16, but I want there to be a table lookup and there to be a redirect to /nice-url-1. Now I would have thought I would go with the second rewrite conditions, but the problem is it just does not redirect.

I am running Centos 6 with Apache 2.2.15, so I am wondering if {REQUEST_FILENAME} is just not supported. I did try adding DOCUMENT_ROOT, but that made absolutely no difference.

Any help most appreciated.

You want to add an other element to your rule, to actually pass the whole url, QSA. This will append the existing query string to the url.

RewriteRule ^ index.php [L,QSA]

I also normally use the single ^ to match any url possible.