PHP脚本的.htaccess重写规则

I have structure php url like:

example.com/category.php?cat=graphics-and-design

and I want to clean the url via a .htaccess rewrite rule to:

example.com/category/graphics-and-design

I tried the following code but still doesn't work:

RewriteRule ^([a-zA-Z0-9_-]*)\/(.*)$ category.php?cat=$1 [L,QSA]

If you don't want problems later with other rules, for example not being able to match example.com/project/foobar without it going to category.php?cat=foobar

Then I suggest you match the category as well:

RewriteRule ^category/(.*)$ category.php?cat=$1 [L,QSA]

If you still want to go down that route (pun intended), the problem is its passing the $1'st match:

example.com/category.php?cat=category

So instead pass match $2

RewriteRule ^([a-zA-Z0-9_-]*)/(.*)$ category.php?cat=$2 [L,QSA]