Forum Moderators: coopster

Message Too Old, No Replies

If $ GET returns nothing, throw an error

         

jake66

3:28 am on Apr 15, 2008 (gmt 0)

10+ Year Member



Way back when I had several pages like: index.php?result=stuff that I no longer use.. a few of them are still indexed.

Instead of manually writing them as:

if ($_GET['result']) =="")
require('404.php'):
}

How can I catch them all at once... basically, if the $_GET pulls no data, throw a 404 regardless of what's in the query string. Some of the query strings only changed the content of the html, not all of them were pulling data from databases so counting rows won't necessarily do the trick.

Is it possible?

penders

11:58 am on Apr 15, 2008 (gmt 0)

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



How can I catch them all at once... basically, if the $_GET pulls no data, throw a 404 regardless of what's in the query string.

I'm not quite sure I understand... if $_GET has no data (ie. empty($_GET)==true) then there is no query string? Or, are you wanting to just check 1 value, ie.

if (!isset($_GET["result"])) {// result is not present}
?

g1smd

9:35 pm on Apr 15, 2008 (gmt 0)

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



You could code this in the .htaccess file.

Set up an external redirect to the canonical URL (301), or a rewrite to an internal filepath that does not exist (404), if the query string is not blank.

The redirect will preserve incoming traffic from external links as well as at least partially transfer any PageRank benefit too.