Try the below:
location ~ ^/catalog/(?P<catnum>\d+)$ {
include fastcgi_params;
fastcgi_param QUERY_STRING category=$catnum;
fastcgi_param SCRIPT_FILENAME $document_root/catalog.php;
fastcgi_pass phpfarm; # replace phpfarm with your FastCGI server
}
location ~ ^/item/(?P<itemnum>\d+)$ {
include fastcgi_params;
fastcgi_param QUERY_STRING category=$catnum;
fastcgi_param SCRIPT_FILENAME $document_root/item.php;
fastcgi_pass phpfarm; # replace phpfarm with your FastCGI server
}
if ($request_uri ~ ^\/catalog\.php\?category=(?P<catnum>\d+)$) {
rewrite ^ $scheme://$http_host/catalog/$catnum? permanent;
}
if ($request_uri ~ ^\/item\.php\?i=(?P<itemnum>\d+)$) {
rewrite ^ $scheme://$http_host/item/$itemnum? permanent;
}
# the below rule is only required if you have further
# rewrite rules that direct anything to the specified
# url
#
# if ($request_uri ~ ^/(catalog|item)/\d+$) {
# break;
# }
Please note that it is not the best implementation. Best would be to change your PHP scripts that they support and handle URL's like "/catalog/12" or "/item/222" directly, instead of "/catalog.php?category=12" and "/item.php?i=12".
If you like, I could change the scripts for you, for a little fee. :)
Hope it helps,
Andrejs