Current API usage: http://api.mydomain.com/v1/names?gender={gender}&age={age}
What I want usage to be: http://api.mydomain.com/v1/names/{gender}/{age}
Can I use .htaccess to rewrite this URL?
Current API usage: http://api.mydomain.com/v1/names?gender={gender}&age={age}
What I want usage to be: http://api.mydomain.com/v1/names/{gender}/{age}
Can I use .htaccess to rewrite this URL?
Assuming both parameters are numeric:
RewriteEngine on
RewriteRule /v1/names/([0-9]+)/([0-9]+) /v1/names?gender=$1&age=$2 [L]
If they can also contain alphanumeric characters replace both instances of [0-9]+
for example with [A-Za-z0-9]+
or whatever fits the requirement.
Apart from that I'd recommend doing this in PHP for more flexibility.
RewriteEngine on
RewriteRule /?v1/names/(.+)/(.+) /v1/names?gender=$1&age=$2 [L]