# If after api / is one word that is the name of the method #
http://site.ru/api/items http://site.ru/api/index.php?method=items
http://site.ru/api/items/ http://site.ru/api/index.php?method=items
# If after api / is 2 words, the first is the method name, and the second is the ID #
http://site.ru/api/items/42 http://site.ru/api/index.php?method=items&id=42
http://site.ru/api/items/42/ http://site.ru/api/index.php?method=items&id=42
# If after api / is one word, followed by a "?" character and a QUERY_STRING, #
# this method name and some parameters from the QUERY_STRING #
http://site.ru/api/items?mode=silent http://site.ru/api/index.php?method=items&mode=silent
http://site.ru/api/items/?mode=silent http://site.ru/api/index.php?method=items&mode=silent
# If after api / is 2 words followed by the sign "?" and a QUERY_STRING, #
# the first is the method name, and the second is the ID #
# and some parameters from the QUERY_STRING #
http://site.ru/api/items/42?mode=silent http://site.ru/api/index.php?method=items&id=42&mode=silent
http://site.ru/api/items/42/?mode=silent http://site.ru/api/index.php?method=items&id=42&mode=silent
# Parameters besides the method id can be anything, and their number is also #
http://site.ru/api/items?mode=silent&foo=bar&fizz=buzz http://site.ru/api/index.php?method=items&mode=silent&foo=bar&fizz=buzz
# Of course, instead of the items can be any other word #
# As is 42 – so they cannot be tied #
RewriteEngine On
RewriteRule ^api/([^/]*)/([^/]*)/$ /api/index.php?method=$1&id=$2 [L]
RewriteRule ^api/([^/]*)/$ /api/index.php?method=$1 [L]
Find more questions by tags ApachehtaccessProcessing URL