Not Found
The requested URL /product.php was not found on this server.
Archivo product.php
Código PHP:
Ver original<?php
require_once 'include/url_redirect.inc.php';
fix_category_product_url();
echo 'You have selected product #' . $_GET['product_id'] .
' from category #' . $_GET['category_id'];
?>
Archivo url_redirect.inc.php
Código PHP:
Ver original<?php
define('SITE_DOMAIN', 'localhost/Apache/Capitulo4');
$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");
function fix_category_product_url()
{
$proper_url = get_proper_category_product_url();
if (SITE_DOMAIN . $_SERVER['REQUEST_URI'] != $proper_url)
{
header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $proper_url); }
}
function get_proper_category_product_url()
{
$product_id = $_GET['product_id'];
$category_id = $_GET['category_id'];
$product_name = $GLOBALS['products'][$product_id];
$category_name = $GLOBALS['categories'][$category_id];
$proper_url = make_category_product_url($category_name, $category_id,
$product_name, $product_id);
return $proper_url;
}
?>
Archivo .htaccess
RewriteEngine On
# Rewrite numeric URLs
RewriteRule ^Products/C([0-9]*)/P([0-9]*)\.html$ /product.php?category_id=$1&product_id=$2 [L]
# Rewrite keyword-rich URLs
RewriteRule ^Products/.*-C([0-9]+)/.*-P([0-9]+)\.html$ /product.php?category_id=$1&product_id=$2 [L]