consistency also makes it easier to exclude files in
, because the preceding problems having
to do with ordering and casing also apply there.
For example, if you’re building an e-commerce web site, you could create a function such as the following:
function create_link($category_id, $product_id)
return ‘product.php?category_id=’ . $category_id . ‘&product_id=’ . $product_id;
Calling this function providing
as parameters, it will return
. Using this function throughout the web site will ensure all your links follow
a consistent format.
This implementation of
is overly simplistic and not really useful for real-world scenarios.
If you want to improve your URLs more significantly, you need to utilize more advanced functions in
coordination with URL rewriting. The benefits of URL consistency will also apply there. So without
further ado, the next section discusses this subject.
Taking into consideration the guidelines and recommendations mentioned earlier, this section presents
solutions you can apply in your web applications to accomplish URL-rewriting using the mod_rewrite
The hurdle you must overcome when implementing the URLs shown earlier is that they don’t actually
exist anywhere in your web site. Your site still contains a script — named, say,
expects to receive parameters through the query string and generate content depending on those param-
eters. This script would be ready to handle a request such as this:
But your web server would normally generate a 404 error if you tried any of the following:
URL rewriting allows you to transform the URL of such an incoming request to a different URL accord-
ing to a defined set of rules. You could use URL rewriting to transform the previous non-existent URLs
From now on, the chapter tends to be very technical. As a rule of thumb, most exer-
cises you’ll find in this book involve writing code, which at times can get quite
complex. We’ve done our best to explain it, but if you don’t have the technical back-
ground assumed by this book — experience with PHP develop
ment — you may
need assistance in following the examples.
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 46
Bitcoin Dice - Crypto Casino . become the expert at paperhelp.org