Forum Moderators: coopster

Message Too Old, No Replies

What to do with PHP variables which don't exist

         

harmhero

1:13 pm on Oct 9, 2011 (gmt 0)

10+ Year Member



I have a multilanguage site:

www.example.com ->usa
www.example.com/index.php?country=FR
www.example.com/index.php?country=ES

$_GET['country'] -> echo countrytext;
if !_GET['country'] -> echo usa-text;

Somehow I made some mistakes in the past and I see pages in Google's index like this:
www.example.com/index.php?country=something-thats-not-in-my-DB

...it shows a blank template of course. How can I:

1) get rid of these 'non-existing' (but existing) pages.
2) prevent it that google indexes these non-existing pages again?

For 1) I am thinking of:


$countries = array("","CA","UK","AU","DE","CH","AT","NL","FR","BE","ES","IT");

if ($_GET['country']) {
$c = $_GET['country'];
} else {
$c = "";
}

if (!in_array($c,$countries)) {

$explode1 = explode(".", $_SERVER['HTTP_HOST']);
$domain = $explode1[0];

$explode2 = explode("?", $_SERVER['REQUEST_URI']);
$goodstring = $explode2[0];

$url = strtolower("http://" . $domain . ".example.com".$goodstring."");

header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");

exit();
}


I am not sure if this is the right thing to do. For 2) I don't know what to do.

g1smd

4:01 pm on Oct 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If someone asks for
country=FRsomejunk
I would redirect to the canonical French URL.

If someone askes for
country=junk
I would return
HEADER "410 Gone"
.

JAB Creations

7:39 am on Oct 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to respectfully disagree with g1smd about the headers, header 410 is intended for pages that previously existed. If a competitor starts linking to pages and search engines see 410 instead of 404 it may cause trouble so only use 410 for pages you've removed and did not implement a redirect or replacement for.

If the value of the HTTP query is not in the array you will want to serve an HTTP 404 response however it does not mean you can't or shouldn't attempt to retain traffic. If time permits I would have the site attempt to generate a small index of links. You can go even further (subjective if you think it will be worth your time) and attempt to guess a close match such as only reading the first two letters as g1smd suggested.

- John