如何重写包含参数的URL?

If user access this URL(http://domain.com/products/view-product.php?productID=21) in browser, it should show the page http://domain.com/new/view-product.php?pID=21

I have tried bellow code but it wont working, so please help me to resolve.

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{THE_REQUEST} products/view-product.php 
RewriteRule ^products/view-product.php?productID=21$ new/view-product.php?pID=21 [R=301,L]

products/view-product.php are physically exists in the server, still i want to rewrite it to the new page that i have designed now.

You can't match against the query string (everything after the ?) in a rewrite rule. Only the URI is used to match against that regular expression. You need to use the condition:

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{THE_REQUEST} products/view-product.php\?productID=21($|\ |&)
RewriteRule ^products/view-product.php$ /new/view-product.php?pID=21 [R=301,L]

GET the value of productID and then redirect to the new URL.

You can match query string using RewriteCond and %{QUERY_STRING} variable. Query string params didn't get to RewriteRule.

RewriteEngine on
RewriteCond %{QUERY_STRING} ^productID=21$
RewriteRule ^products/view-product\.php$ /new/view-product.php?pID=21 [R=301,L]

Or if you want to redirect all productID's:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^productID=([0-9]+)$
RewriteRule ^products/view-product\.php$ /new/view-product.php?pID=%1 [R=301,L]