Make post title as a slug in url by mod rewrite

I have previously posted a question but I am not satisfied with the answers. I have a url, for example

http://example.com/details.php?a=100&b=101&slug=power-programming-in-php

I want to write it by rewrite rule as

http://example.com/power-programming-in-php

I am currently using a rule :

RewriteRule ^([a-zA-Z0-9]*-[a-zA-Z0-9]*)$  paper-ads-details.php?a=$1&b=$2&slug=$3   [L]

I am now stuck, does anyone have any suggestions?


At the very least your RewriteRule is faulty in that it refers to three different callback variables but you only have one group match to reference! Where the 100 and 101 values for a and b are supposed to come from one can only guess. Also the regular expression you wrote won't match the example you gave because it has four sets of dashes, not one. Try this instead:

RewriteRule ^([-a-zA-Z0-9]+)$  /paper-ads-details.php?a=100&b=101&slug=$1   [L]

Note that since I started the character class [] with a dash, the dash is understood as adding a litteral dash to the list of options instead of denoting a range between other characters as in the a-z syntax. This only works because it's the first character. My rule should match a string with any number of dashes, but without any periods along. If a period or other character turns up, it should revert to normal url matching.