JavaScript Editor Ajax software     Free javascripts 



Main Page

the individual product pages. These URLs are “hackable,” in that the products will be placed in an
intuitive-looking directory structure. Users can intuitively modify such URLs to navigate the site.
Rewriting Keyword-Rich URLs
1.
Modify the
.htaccess
file in your
seophp
folder like this:
RewriteEngine On
# Rewrite numeric URLs
RewriteRule ^Products/C([0-9]*)/P([0-9]*)\.html$
i
/product.php?category_id=$1&product_id=$2 [L]
# Rewrite keyword-rich URLs
RewriteRule ^Products/.*-C([0-9]+)/.*-P([0-9]+)\.html$
i
/product.php?category_id=$1&product_id=$2 [L]
2.
Load
http://seophp.example.com/Products/Tools-C5/Super-Drill-P9.html
, and
voila, you should get the result that’s shown in Figure 3-12.
Figure 3-12
You currently have two rules in your
.htaccess
file, and they are working beautifully!
The new rule matches URLs that start with the string
Products/
, then contain a number of zero or more
characters (
.*
) followed by
–C
. This is expressed by
^Products/.*-C
. The next characters must be one
or more digits, which as a whole are saved to the
$1
variable, because the expression is written between
parentheses —
([0-9]+)
. This first variable in the URL,
$1
, is the category ID.
After the category ID, the URL must contain a slash, then zero or more characters (
.*
), then
-P
, as expressed
by
/.*-P
. Afterward, another captured group follows, to extract the ID of the product,
([0-9]+)
, which
becomes the
$2
variable. The final bit of the regular expression,
\.html$
, specifies the URL needs to end
in
.html
.
The two extracted values,
$1
and
$2
, are used to create the new URL,
/product.php?category_id=
$1&product_id=$2
. Figure 3-13 describes the process visually.
65
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 65


JavaScript Editor Ajax software     Free javascripts 
Bitcoin Dice - Crypto Casino