RewriteMap WILL do that if you have access to the server or vhosts file. However, because any coding error can bring down the server, you should not attempt this unless you know what you're doing.
You can do the same thing, though, using a PHP handler file (redirect to the handler thence on to the file you want to serve based on the input). I'd covered this before in this board and it should also be in the tutorial linked in my signature. FWIW, I call it a "Poor Man's RewriteMap."