JavaScript Editor Ajax software     Free javascripts 



Main Page

5.
At this moment the image rewriting works perfectly. However, in order to implement it in a
real-world web site you also need to extend the URL factory to build the image file names for
you. Open the URL factory file,
url_factory.inc.php
, and add this function to it:
// builds a link to a media file
function make_media_url($id, $name, $extension)
{
// prepare the medium name for inclusion in URL
$clean_name = _prepare_url_text ($name);
// build the keyword-rich URL
$url = SITE_DOMAIN . ‘/‘ . $clean_name . ‘-M’ . $id . ‘.’ . $extension;
// return the URL
return $url;
}
6.
Open
cartoons.php
, and change the hard-coded file names to calls to the
make_media_url()
function, like this:
<?php
// load the URL factory library
require_once ‘include/url_factory.inc.php’;
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<html>
<head>
<title>URL Rewriting Media Files</title>
</head>
<body>
<img src=”<?php echo make_media_url(1, “Tweety”, “jpg”); ?>” alt=”Tweety” />
<img src=”<?php echo make_media_url(2, “Toy Story”, “jpg”); ?>” alt=”Toy Story”
i
/>
<img src=”<?php echo make_media_url(3, “Tweety & Sylvester”, “jpg”); ?>”
i
alt=”Tweety & Sylvester” />
<img src=”<?php echo make_media_url(4, “Mickey”, “jpg”); ?>” alt=”Mickey” />
<img src=”<?php echo make_media_url(5, “Minnie”, “jpg”); ?>” alt=”Minnie” />
</body>
</html>
7.
Load
http://seophp.example.com/cartoons.html
again. Expect to get the same links as
before, and the results shown in Figure 3-16.
The exercise was pretty much similar to the previous ones, except Apache rewrites the image URLs to
physical files on your disk. The regular expression looks a bit more complicated this time, but it’s really
not very different from the other ones you’ve dealt with:
RewriteRule ^.*-M([0-9]+)\..*$ /media/$1 [L]
74
Chapter 3: Provocative SE-Friendly URLs
c03.qxd:c03 10:39 74


JavaScript Editor Ajax software     Free javascripts