Prev | Current Page 295 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

The enclosing parentheses around [0-9]+ indicate that the regular expression engine
should store the matching string (which will be the department ID) inside a variable called $1.
You??™ll need this variable to compose the rewritten URL.
The same principle is used to save the category ID and the page number into the $2 and $3
variables. Finally, you have /?, which specifies that the URL can end with a slash, but the slash
is optional. The regular expression ends with $, which matches the end of the string.
?– Note When you need to use symbols that have metacharacter significance as their literal values, you need
to escape them with a backslash. For example, if you want to match index.php, the regular expression
should read index\.php. The \ is the escaping character, which indicates that the dot should be taken as
a literal dot, not as any character (which is the significance of the dot metacharacter).
The second argument of RewriteRule, index.php?DepartmentId=$1&CategoryId=$2&Page=$3,
plugs in the variables that you extracted using the regular expression into the rewritten URL.
The $1, $2, and $3 variables are replaced by the values supplied by the regular expression, and
the URL is loaded by our application.
A rewrite rule can also contain a third argument, which is formed of special flags that affect
how the rewrite is handled. These arguments are specific to the RewriteRule command and
aren??™t related to regular expressions.


Pages:
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307