As you learned in the previous exercise, a basic
takes two arguments. In this example it also
received a special flag —
— as a third argument. The meaning of these arguments is discussed next.
The first argument of
is a regular expression that describes the
want to rewrite. The second argument specifies the destination (
) URL. So, in geek-speak, the
line basically says: rewrite any URL that
. In English, the same line can be roughly read as: “dele-
gate any request to a URL that looks like
Let’s analyze in detail the regular expression that describes the matching URLs that need to be rewritten.
That regular expression is:
Most characters, including alphanumeric characters, are read literally and simply match themselves.
Remember the first
you’ve written in this chapter to match
which was mostly created of such “normal” characters.
What makes regular expressions so powerful (and sometimes complicated), are the special characters (or
), such as
, which have special meanings. Table 3-3 describes the metacharacters
Remember that this theory applies to regular expressions in general. URL rewriting is just one of the
many areas where regular expressions are used.
Table continued on following page
Matches the beginning of the line. In our case, it will always match the beginning of
the URL. The domain name isn’t considered part of the URL, as far
concerned. It is useful to think of
as “anchoring” the characters that follow to the
beginning of the string, that is, asserting that they be the first part.
Matches any single character.
Specifies that the preceding character or expression can be repeated zero or more
times — not at all to infinite.
Specifies that the preceding character or expression can be repeated one or more
times. In other words, the preceding character or expression must match at least
Specifies that the preceding character or expression can be repeated zero or one
time. In other words, the preceding character or expression is optional.
Specifies that the preceding character or expression can be repeated between
are integers, and
needs to be lower than
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 57