JavaScript Editor Ajax software     Free javascripts 



Main Page

Using Table 3-2 as reference, analyze the expression
^Products/P([0-9]*)\.html$
. The expression
starts with the
^
character, matching the beginning of the requested URL (remember, this doesn’t include
the domain name). The characters
Products/P
assert that the next characters in the URL string match
those characters.
Let’s recap: the expression
^Products/P
will match any URL that starts with
Products/P
.
The next characters,
([0-9]*)
, are the crux of this process. The
[0-9]
bit matches any character between
0 and 9 (that is, any digit), and the
*
that follows indicates that the pattern can repeat, so you can have an
entire number rather than just a digit. The enclosing parentheses around
[0-9]*
indicate that the regular
expression engine should store the matching string (which will be a number) inside a variable called
$1
.
(You’ll need this variable to compose the rewritten URL.)
Finally, you have
\.html$
, which means that string should end in
.html
. The
\
is the escaping charac-
ter, which indicates that the
.
should be taken as a literal dot, not as “any character” (which is the signif-
icance of the
.
metacharacter). The
$
matches the end of the string.
The second argument of
RewriteRule
,
/product.php?product_id=$1
, plugs the variables that you
stored into your script URL mapping, and indicates to the web server that requests by a browser for
URLs matching that previous pattern should be delegated to that particular script with those numbers
substituted for
$1
.
Metacharacter Description
( )
The parentheses are used to define a
captured expression
. The string matching the
expression between parentheses can then be read as a variable. The parentheses
can also be used to group the contents therein, as in mathematics, and operators
such as
*
,
+
, or
?
can then be applied to the resulting expression.
[ ]
Used to define a character class. For example,
[abc]
will match any of the charac-
ters
a
,
b
,
c
. The
-
character can be used to define a range of characters. For example,
[a-z]
matches any lowercase letter. If
-
is meant to be interpreted literally, it should
be the last character before
]
. Many metacharacters lose their special function when
enclosed between
[
and
]
, and are interpreted literally.
[^ ]
Similar to
[ ]
, except it matches everything except the mentioned character class.
For example,
[^a-c]
matches all characters except
a
,
b
, and
c
.
$
Matches the end of the line. In our case, it will always match the end of the URL.
It is useful to think of it as “anchoring” the previous characters to the end of the
string, that is, asserting that they be the last part.
\
The backslash is used to escape the character that follows. It is used to escape
metacharacters when you need them to be taken for their literal value, rather
than their special meaning. For example,
\.
will match a dot, rather than “any
character” (the typical meaning of the dot in a regular expression). The backslash
can also escape itself — so if you want to match
C:\Windows
, you’ll need to refer
to it as
C:\\Windows
.
58
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 58


JavaScript Editor Ajax software     Free javascripts 
Bitcoin Dice Site . https://paperhelp.link/