如何防止机器人遵循GET形式?

I have the following form in my index.php:

<form action="index.php" method="GET">  
    <input name="id" type="text">
</form>

I know that I can change the method to POST, so that googlebot (or any other bot) won't submit this. However I need this to be a GET form.

  • I have set noindex and nofollow when $_GET["id"] is submitted (i.e. on index.php?id=123)
  • index.php has index and follow, because I want the rest of the site to be followed and indexed.

I'm looking for a way to prevent googlebot from entering the index.php?id='some random number'

Just do a simple test and return a 404 header. Granted, this is not terribly efficient, but it will work for what you want

if(isset($_GET['id']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false) {
    header("HTTP/1.0 404 Not Found");
    exit;
}