To be a bit more flexible what you're probably looking for is mod_rewrite. You can find documentation for it here http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html. It can be a little confusing but with a little testing you should get exactly what you're looking for.
Caro.Net: Support is everything
Offering High Quality Dedicated Servers.