JavaScript Editor Ajax software     Free javascripts 



Main Page

consistency also makes it easier to exclude files in
robots.txt
, 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
5
and
6
as parameters, it will return
product.php?category_
id=5&product_id=6
. Using this function throughout the web site will ensure all your links follow
a consistent format.
This implementation of
create_link()
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.
URL Rewriting
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
Apache module.
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,
product.php
— which
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:
http://seophp.example.com/product.php?product_id=123
But your web server would normally generate a 404 error if you tried any of the following:
http://seophp.example.com/Products/123.html
http://seophp.example.com/my-super-product.html
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
to
product.php?product_id=123
, which
does
exist.
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.
46
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 46


JavaScript Editor Ajax software     Free javascripts 
Bitcoin Dice - Crypto Casino