JavaScript Editor Ajax software     Free javascripts 

Main Page

Redirecting Dynamic URLs to Keyword-Rich URLs
Add this code to your
file. These global associative arrays define a line of
products and categories, simulating a real product database. You’ll need the data from these
arrays to generate the keyword-rich versions of URLs automatically, using PHP code. (Arrays
are used instead of a real database to keep the exercise easier for you to follow.)
// site domain; no trailing ‘/‘ !
define(‘SITE_DOMAIN’, ‘;
// create a fictional database with products and categories
$GLOBALS[‘products’] = array
(“45” => “Belt Sander”,
“31” => “Link Juice”,
“42” => “AJAX PHP Book”);
$GLOBALS[‘categories’] = array
(“12” => “Carpenter’s Tools”,
“6” => “SEO Toolbox”,
“2” => “Friend’s Shed”);
and type this code:
// load the URL factory library
require_once ‘’;
// redirects to proper URL if not already there
function fix_category_product_url()
// obtain the proper URL of the current category/product page
$proper_url = get_proper_category_product_url();
// 301 redirect to the proper URL if necessary
if (SITE_DOMAIN . $_SERVER[‘REQUEST_URI’] != $proper_url)
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: ‘ . $proper_url);
// returns the proper keyword-rich URL
function get_proper_category_product_url()
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 86

JavaScript Editor Ajax software     Free javascripts 
Bitcoin Gambling Site