The web site application should be retrofitted with
. All instances of a web site
application’s code where URLs are displayed should be replaced. For example (assume the following
variables refer to product database information):
These kinds of instances should be changed to:
echo make_product_url($category_name, $category_id, $product_name, $product_id);
We’ve demonstrated how you can do this by creating a fictional catalog page of an e-commerce web site,
, and we’ve even created a rewrite rule for it so you could access it using a static URL.
In a real-world web site the product and category names and IDs would be retrieved from the database,
but for the purposes of this exercise we’ve typed them by hand to simplify the example.
<a href=”<?php echo make_category_product_url(“Carpenter’s Tools”, 12, ‘Belt
Sander’, 45); ?>”>
Carpenter’s Tools: Belt Sander
Pagination and URL Rewriting
It is often necessary to paginate series of pages on a web site. Ideally, the URLs of those the pages should
also be rewritten. This rule is not illustrated in action until the e-commerce store in Chapter 14, but here
is the rule to whet your appetite:
Rewriting Images and Streaming Media
Some recommend using keywords not only in HTML document names, but also embedded in the image
and media file names. Especially if you are in the image and streaming media distribution business, this
may be more important.
Depending on your particular application, you may find it easier to use proper physical file names.
However, if the solution is more complex, rewriting image file URLs may make sense. Rewriting can be
accomplished here with little effort. All files should be placed in one directory with only ids as their file
names, that is, (“1”, “2”, “3”) — no extensions. You delegate the requests
to physical files on the
file system — and not through a PHP application. You do this because streaming media use extensions
in a web server that cannot be easily implemented in PHP scripts. The URLs are generated using a PHP
function as in previous examples.
Rewriting Image Files
folder from the code download to your
folder. In your
folder, you should have five files named
. These are jpeg image files.
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 72
Bitcoin Gambling Site