In the Apache and PHP
world, this is implemented using an Apache module named mod_rewrite, which can intercept
URLs that follow a certain pattern and rewrite the requests to another URL that can be processed
by your application. This process is called URL rewriting.
Even when doing URL rewriting, the final file that gets executed is a script, such as index.php
in our case. But the same script can be accessed using a nicer-looking URL.
Figure 7-1 shows a simple example of URL rewriting. As you can see, the mod_rewrite
module intercepts the URL requested by the visitor and rewrites it to a dynamic URL that your
application can understand. The PHP script executes, and the results are sent back to our users,
who are (obviously) very happy to get the content they want.
Figure 7-1. A URL rewriting example with Apache and mod_rewrite
There are several ways to translate the keyword-rich URL to its dynamic version for execution.
In TShirtShop, we??™ll apply a technique that is both effective and simple to implement:
we??™ll hide the item ID in the keyword-rich version of the URLs, such as in http://localhost/
tshirtshop/visit-the-zoo-p36/. This keyword-rich URL contains the product ID hidden inside
in a way that doesn??™t hinder its readability for humans and search engines alike.
User req er requests
http://www.example.com/vi visit-the-zoo/
it-Apache we web server erver
pro produ duct.
Pages:
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296