mod_rewrite in .htaccess file for unknown first part of path

view story

http://serverfault.com – I am trying to write a rewrite rule to change path slugs to query parameters. It is for a web service, and should only rewrite this rule if the host starts with api. There are two slugs that I am trying to capture and rewrite. The first is optional and is a version (i.e. v1.2) and the second is the service domain (i.e. customers, transactions, etc.). http://api.domain.com/v2.5/customers should rewrite to ?version=2.5&domain=customers I also want to support a default version so that http://api.domain.com/customers should rewrite to ?version=&domain=customers Here is what my .htacce (HowTos)