RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9]+)/(.*?).html$ /article.php?articleid=$1&categoryid=$2
I’ve been trying to find a site that explains what each part of this code does but I can’t seem to find it. I understand some of the regular expression, but can’t seem to grasp what “$1” or “$2” are for. what do those do? What does the “^” and “$” after the .html serve?
RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9]+)/[B](.*?)[/B].html$ /article.php?articleid=$1&categoryid=$2
I have some doubt of above code at part B[/B]. cos * is quantifier or ? is also quantifier, for (.*) or (.?) is quit enough to someone need. what about B[/B]? I don’t understand this part.
RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9]+)/[B](.*?)[/B][SIZE="5"][COLOR="Blue"]\\[/COLOR][/SIZE].html$ /article.php?articleid=$1[SIZE="5"][COLOR="Red"]&[/COLOR][/SIZE]categoryid=$2 [SIZE="5"][COLOR="Blue"][L][/COLOR][/SIZE]
The above code in red MUST be &, not the HTML version of the & character! The blue code (Last flag) is necessary to terminate your mod_rewrite block statement the same way that ; is commonly used in programming languages. Also, escape the dot character in the regex.
(.?) is the non-greedy version of (.) but the ? is really irrelevant as you’ve specified EVERYTHING up to but NOT including .html at the end of the {REQUEST_URI} string. In this case, the ? is the modifier of the * metacharacter, otherwise, it would be the metacharacter for zero or one of the preceding character.
In this case, the ? is the modifier of the * metacharacter, otherwise, it would be the metacharacter for zero or one of the preceding character.
, B[/B] is quit enouch to what…, but not (.*?)
cos ? have to modify to preceeding metacharacter like . , but not +, *
. is identified for any characters, but * is not identified for any characters, but just modifier for any characters…
using +? or *? is the “non-greedy” form of the “greedy” metacharacter
What does that mean for regex within mod_rewrite? NOTHING! I can’t see any use for the ? as a metacharacter modifier in mod_rewrite. It IS, however, very useful in parsing text strings in scripts. Have a read of Friedl’s Mastering Regular Expressions, it’s the definitive treatment of Regex.