URl用nginx和PHP重写

I have a large number of product id URL

domain.com/product.php?product_id=123&app_data=xyz123

My use case is to rewrite those URL to below format

/product/productid/appdata

I have written a rewrite rule.

rewrite ^/product/productid/(.*)        /product.php?product_id=$1&$query_string last;

But when I hit

domain.com/product.php?product_id=123412&app_data=cHJvZHVjdF9pZD0xODc2NTEmZGVmU2 

It doesn't rewrite to

domain.com/product/productid/appdata

Rewriting happens entirely on the server, it takes A to B, as in

rewrite A B

If A is domain.com/product.php?product_id=123412&app_data=cHJvZHVjdF9pZD0xODc2NTEmZGVmU2, then you're doing it backwards.

Try:

location / { 
  if ($query_string ~ "^product_id=([^&]+)&app_data=([^&\ ]+)") { 
    rewrite ^/product.php$ /product/%1/%2? redirect; 
  } 
} 

location /product { 
  rewrite ^/product/([^/]+)/([^/]+)$ /product.php?product_id=$1&app_data=$2 break; 
}

It's unclear if you want redirect or internal rewrite. First case:

location /product.php {
    rewrite 301 http://domain.com/product/$arg_product_id/$arg_app_data;
}

Second:

location / {
    rewrite ^/product.php$ http://domain.com/product/$arg_product_id/$arg_app_data last;
}