Your first regular expression (RE)

To really understand ISAPI as opposed to Mod_Rewrite you need to know that all RewriteRule lines start with the ^ (caret). In regular expressions, the caret matches at the start of the string the regex pattern is applied to and matches a position rather than a character. Most regex flavors have an option to make the caret match after line breaks (i.e. at the start of a line in a file) as well. So, although I can find no documentation on the subject I assume the caret takes the place of the standard URL (http://foo.bar.com) up to but not including the first forward slash after the URL. I do know for certain that if you don't use it your INI file is practically worthless.

In order to really understand ISAPI, you need to start using regular expressions. If you are completely in the dark about regular expressions, I suggest reading up on the subject before you attempt to learn how to use ISAPI, but I will give a short intro to Regular Expressions here: http://www.regular-expressions.info/reference.html. A Regular Expressions is a sort of extremely flexible wildcard search that has its own set of symbols for matching pretty much any string.

A basic wildcard search would be something like this: *.html which would find any file that ends with .html.

Regular expressions do the same sort of thing, but as I said, are much more flexible. The same search with regex would look like this: .*\.html$

In the regex above, the . (dot) matches any single character, the * (asterisk) matches 0 or more of the preceding character, since we are looking for a literal dot, the . Before html must be escaped, and finally the $ (dollar sign) means the string should end.

More Regex Rules abc would match abc a sequence of characters enclosed by brackets matches only one character: [abc] would match: 'a', 'b', or 'c' [a-z] matches any lowercase character from a - z [0-9] matches any number the '*' asterisk after any character will match 0 or more occurrences of the preceding character, while the '+' will match 1 or more. so [a-z]* will match 0 or more lowercase letters in a row. like :'aajfalsdjflasdjfalsdjfalsdfj' [a-zA-Z0-9_-]+ would match 1 or more of the characters shown within the brackets. The dot (.) is kind of like a wildcard and matches a single character, except line break characters.

ISAPI also can leverage grouping in regular expressions. () parenthesis are used to define a group. Anything you put in a group goes into a variable. So if you had somthing like:

/prod.asp?pid=6435&color=green&size=medium to this /products/6435/green/medium This is what you would use:

RewriteRule ^products/([0-9]+)/([a-z]+)/([a-z]+)$ /prod.asp?pid=$1&color=$2&size=$3

As you can see there are 3 groups. 1. ([0-9]+) , ([a-z]+) , and ([a-z]+) these 3 are put into the variables: $1, $2, and $3 So to summarize, what you are doing with a ISAPI is asking your web server to check each url when it comes in, to see if it matches the pattern products/([0-9]+)/([a-z]+)/([a-z]+)$, then its going to get sent to /prod.asp?pid=$1&color=$2&size=$3 with the variables from the groups.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner