Forum Moderators: coopster

Message Too Old, No Replies

Making sure URL is unique Catching any Duplicates

         

appi2

3:32 pm on Nov 14, 2006 (gmt 0)

10+ Year Member



g1smd made me think ;)
[webmasterworld.com...]

A lot of sites show a list of products on a page.
Then if a user clicks on one of the products the same page is used to show only that product.

I did use something like the code below

animals.php

if (isset($_GET[Product])) {
require ('single-product.php');
else
{
require('list-products.php');
}

eg
Typical url
http:// www.yourdomain.com/animals.php
show all animals 200 ok

http:// www.yourdomain.com/animals.php?Product=wombat
show only the wombat 200 ok

Now problems!
http:// www.yourdomain.com/animals.php?Product=dodo
dodo is extinct tell the user. 200 ok

http:// www.yourdomain.com/animals.php?Product=dinosaur
dinosaur is extinct tell the user. 200 ok

Were stepping into duplicate issues, two url's and possibly the same content on the page.
The database couldn't return any unique content.

More problems
http:// www.yourdomain.com/animals.php?Producttype=wombat

If we used the code above it would default to the

http:// www.yourdomain.com/animals.php and show 200 ok

as would

http:// www.yourdomain.com/animals.php?anythingyouwanthere=foo

Whats below is me just trying to avoid the above.
animals.php
<?php
###############################
# 'single-product.php' checks the database to see if the product exists
# and pulls out the 'unique' description, title, meta etc for that product.
# If it doesn't exist that page should actually redirect by 301 to product-gone.php
# to avoid duplication problems. And maybe add a robots no index meta tag
# to the product-gone.php page.

if (isset($_GET[Product])) {
require ('single-product.php');
}

#
################################

################################
# Next
# Protects? against a url like http:// www.yourdomain.com/animals.php?product=wombat
# Notice "product" not "Product" Taken from a post on threadwatch about a msn flaw.
# The duplicate google thing would apply as well, I assume!
#

elseif($_GET) {
ignore_user_abort(true);
header ("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("HTTP/1.1 301 Moved Permanently");
header("Location: http:// www.yourdomain.com/animals.php ");
header("Connection: close");
exit;
}

#
#################################

#################################
# Were now expecting a url like http:// www.yourdomain.com/animals.php
# And should have caught any duplicates.
#

else
{
require('list-products.php');
}

#
#############################
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
...

Did I get it right?

barns101

3:57 pm on Nov 14, 2006 (gmt 0)

10+ Year Member



You could list your categories in an array and only allow the script to continue if?Product is one of those values.

When an invalid request is made I return a 404 error, although I use mod_rewrite in the first instance to make it appear that a static page is being requested.