在Apache中用两个参数重写查询字符串

I usually don't use Apache, but here I kind of have to. I am having trouble rewriting an URL that takes two parameters over the query string and rewrites it.

The original URL is: products.php?artist={artist_slug}&product={product_slug} and I would like to rewrite it to /artists/{artist_slug}/products/{product_slug}.

The rewrite RewriteRule ^artists/([a-zA-Z0-9-]*)/ /artist.php?artist=$1 works fine, but as soon as I extend from that forward to

RewriteRule ^artists/([a-zA-Z0-9-]*)/products/([a-zA-Z0-9-]*)/ /products.php?artist=$1&product=$2

it throws me a 404. Does anybody know what I am doing wrong? Thanks for your help in advance.

Try using this rule instead:

RewriteEngine On
RewriteCond %{QUERY_STRING} artist=(.*)&product=(.*)$ [NC]
RewriteRule ^ http://%{HTTP_HOST}/artists/%1/products/%2? [R=301,L]

This grabs both of the query strings and then rewrites them to the following URL http://example.com/artists/{artist_slug}/products/{product_slug}. You'll see I've added a ? onto the end of the Rewrite. That is to stop the query_string from appearing on the end of the URL.

Make sure you clear your cache before testing this.