JavaScript Editor Ajax software     Free javascripts 

Main Page

Figure 3-13
Building a Link Factory
Back in the days when you worked only with dynamic URLs, it was easy to build the URLs right in
the application code without much planning. You cannot do that here. If you want to use keyword-rich
URLs in your web site, just having a
in your
file isn’t enough! You also need
to ensure that all the links in your web site use these keyword-rich versions consistently throughout the
web site. Obviously, including the URLs manually in the web site is not an option — it’s a dynamic site
after all, and the link management task would quickly become impossible to handle when you have a
large number of products in your catalog!
Fortunately, there’s a very straightforward solution to this problem, which as soon as it’s put in place,
takes away any additional link management effort. The solution we’re proposing is to use a function to
generate the new URLs based on data already existing in your database, such as product or category
names. As mentioned before, this also enforces consistency.
Say that you have a product called Super Drill, located in the category Tools. You know the product ID
is 9, and the category ID is 5. It’s quite easy to create a PHP function that uses this data to generate a link
such as
In the exercise that follows you create and then use two PHP functions:
receives as a parameter a string that will be included into the beautified
URL, such as a product or category name, and transforms it into a form that can be included in
a URL. For example, this function would transform Super Drill to Super-Drill.
takes as parameters the names of a product and a category, and their IDs,
and uses the
function to generate a URL such as
translates request
PHP script executes
Client requests URL
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 66

JavaScript Editor Ajax software     Free javascripts 
Bitcoin Dice Site