Forum Moderators: phranque
I think it's an easy fix.. but then again like I said, I'm new to mod_rewrite and don't really know the best way to approach things.
-----------------------------------------
What I'm trying to do is rewrite:
video.php?do=viewcategory&categorytitle=XX&categoryid=XX
to
video/category/XX-XX
An example would be:
video.php?do=viewcategory&categorytitle=after-school&categoryid=3
to
video/category/after-school-3
The rule I have is:
RewriteRule ^video/category/([a-z0-9_\-]*)([0-9])$ video.php?do=viewcategory&categorytitle=$1&categoryid=$2&sort=dateline&order=ASC [L]
The Problem:
It seems to work for the category IDs 1 through 9.. Anything higher than 9 though, as in 2 or 3 digit IDs, don't work.. And instead the last digit is used as the category ID..
So category 33 would come out as category 3..
I'm really not sure how to fix this, and I don't think it's a hard fix.. so any help would be greatly appreciated.
Thanks,
Peter (Munkii)
You need to add a quantifier to make subpatterns such as "[0-9]+". Use "+" to match one or more digits, or specify a minumum,maximum range by using an explicit quantifier range, for example "{2,9}". You may also omit either the minimum or the maximum if you wish.
You may also use a quantifier of "*" which will match zero or more characters. As you have found though, it causes problems because it is maximally-greedy, and will consume *all* characters in the string to be matched if you allow it to do so, leaving the next sub-pattern to "starve." I suspect you won't be able to allow numbers in the 'title' if you want to use a simple pattern for the title. Otherwise, you'll need something more complex like:
^video/category/(([a-z0-9_]+-)+)([0-9]+)$ See the concise regular-expressions tutorial cited in our Forum Charter for details.
Jim