JavaScript Editor Ajax software     Free javascripts 



Main Page

The web site application should be retrofitted with
make_product_url()
. 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):
echo “/products.php?category_id=$category_id&product_id=$product_id”;
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,
catalog.php
, 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
i
Sander’, 45); ?>”>
Carpenter’s Tools: Belt Sander
</a>
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:
RewriteRule ^Products/.*-C([0-9]+)/Page-([0-9]+)/?$
i
category.php?category_id=$1&page_num=$2 [L]
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
directly
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
1.
Copy the
media
folder from the code download to your
seophp
folder. In your
seophp/media
folder, you should have five files named
1
,
2
,
3
,
4
, and
5
. These are jpeg image files.
72
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 72


JavaScript Editor Ajax software     Free javascripts 
R7