I have a code like this:
echo " <td width='57%' height='126' class='bord' ><a href='$category_name-$id.htm'
class='title_style'>" . $title . "</a><br />
";
So, $category_name is the name of categories from database. So it changes!
I need to rewrite it using RewriteRule. I’ve tried something like this
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-]+)-([0-9]+)\.htm$ classified.php?id=$1 [L]
EX:
Let say $category_name = Cars and $id =15 then the url should look: Cars-15.htm
I thank you in advance
I suspect you only wanted to get the numeric part of the incoming path name.
Your regex is correct so far, but you used the wrong placeholder.
$1is for the first capture group, the category in your case. And$2contains the second match groups content, the numeric id.So your RewriteRule ought to be:
Which could be simplified further btw:
(Though also matches underscores in the category part then.)