第一个破折号未被识别为分隔符

A have a problem with url rewriting. I have this url:

http://www.example.com/apps/1-health-directory

With this rule:

RewriteRule ^apps/([^_]*)-([^_]*)$ /app_details.php?id=$1&name=$2 [L,QSA,NC]

The problem is that when I want to get the id and name param, this is what is returned:

app_details.phpid=1-health&name=directory

And the correct it would be

app_details.phpid=1&name=health-directory

How can be done?

Thx

Your regex is incorrect. You're trying to match until first dash then use [^-] instead of [^_] (dash != underscore)

Try this rule:

RewriteRule ^apps/([^-]*)-(.*)$ /app_details.php?id=$1&name=$2 [L,QSA,NC]