But as I say, the current site has over 100 products with + in the title and they all work fine. But now... with this new structure, they don't. On the product page, I've not added anything to make it 301.
I've found what is making it do it, but not 'why' it is doing it.
I have this script in an external included file, that takes the page back to a subcategory if the product doesn't exist. And it checks that the product title is correct.
Maybe it's this?? As this is not on the LIVE version. If it is this, how can I get around the problem?
Code: Select all
<?php
$myprod = isset($_GET['product']) ? $_GET['product'] : null;
if (isset($myprod))
{
// gather $h which has the title in the url, and remove the hyphen.
$h = isset($_GET['h']) ? $_GET['h'] : null;
$h = str_replace("-"," ",$h);
$sname = isset($_GET['sname']) ? $_GET['sname'] : null;
$cname = isset($_GET['cname']) ? $_GET['cname'] : null;
// check if the product ID exists at all
$queryid = "SELECT id, catid, subid, catname, subname, title FROM products WHERE id = :myprod";
$stmtid = $pdo->prepare($queryid);
$stmtid->execute(array(':myprod' => $myprod));
// if it doesn't exist, 301 to the URLs subcategory page (let the subcategory page handle it beyond that
if ($stmtid->rowCount() == 0)
{
header("Location: /subcateg/$cname/$sname", TRUE, 301);
exit();
}
else
{
// if the ID is correct, it then checks if the title is correct. If it is NOT right, it rewrites it from the database.
// else it just ignores this whole thing and passes it through
$query = "SELECT id, catid, subid, catname, subname, title FROM products WHERE title = :h";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':h' => $h));
if ($stmt->rowCount() == 0)
{
while ($row = $stmtid->fetch(PDO::FETCH_OBJ))
{
$title = str_replace(" ","-",$row->title);
header("Location: /product/$cname/$sname/$row->id/$title", TRUE, 301);
exit();
}
}
}
}
?>