JavaScript Editor Ajax software     Free javascripts 



Main Page

Redirecting Dynamic URLs to Keyword-Rich URLs
1.
Add this code to your
config.inc.php
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.)
<?php
// site domain; no trailing ‘/‘ !
define(‘SITE_DOMAIN’, ‘http://seophp.example.com);
// 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”);
?>
2.
Create
include/url_redirect.inc.php
and type this code:
<?php
// load the URL factory library
require_once ‘url_factory.inc.php’;
// 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);
exit();
}
}
// returns the proper keyword-rich URL
function get_proper_category_product_url()
{
86
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 86


JavaScript Editor Ajax software     Free javascripts 
Bitcoin Gambling Site