Getting a redirect to be nofollow ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    Getting a redirect to be nofollow ?

    Hi,

    I am using a dynamic redirect to take vistors to the database stored
    url as in this part of the script:


    Code:
      $sql = "SELECT ad_link FROM adverts WHERE advert_id = $N_ad_id";
         $result = mysql_query($sql)    or die("could not execute find PRODUCTS query". mysql_error());  
             $num = mysql_num_rows($result);
    
             if ($num == 0 ) {
             echo "There an ERROR in locating this product.";
           }  // endif    
             else{       
                $row = mysql_fetch_assoc($result);
                    $N_ad_link = "http://".$row["ad_link"];
        
    $sql = "UPDATE adverts SET click_cnt = click_cnt+1 WHERE advert_id = $N_ad_id";
    mysql_query($sql) or die("could not execute adverts update query". mysql_error());
    
    header("Location: $N_ad_link");
    exit();
    Now I want to ensure that search engine robots and web crawlers do not
    index these links. Can I insert a bit of html code to accomplish this ?

    EG

    Code:
    $sql = "UPDATE adverts SET click_cnt = click_cnt+1 WHERE advert_id = $N_ad_id";
    mysql_query($sql) or die("could not execute adverts update query". mysql_error());
    
    echo "
    <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
     \"http://www.w3.org/TR/html4/loose.dtd\">
    
    <html>
    <head>
    <title>Temp Page</title>
    <meta name=\"allow-search\" content=\"no\">
    <meta name=\"robots\" content=\"all, noindex, nofollow\">
    </head>
    <body>
    header(\"Location: $N_ad_link\");
    </body>
    </html>";
    
    exit();
    I have escaped the double quotes because they are inside the
    echo statement.

    Is the header(\"Locati on: $N_ad_link\"); in the correct place ?
    Do you think this is the best way to do it ?

    Thanks for any advice.

    PS
    Maybe I should use a meta-refresh instead:

    So in the above html I will put:

    Code:
    echo "<html>
    <head>
    <title>Temp Page</title>
    <meta name=\"allow-search\" content=\"no\">
    <meta name=\"robots\" content=\"all, noindex, nofollow\">
    <meta http-equiv ='refresh' content = '0;url = $N_ad_link'>
    </head>
    <body>
    </body>
    </html>";
    Is this a better method ?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Second example will you a 'headers already sent' error.

    I believe setting the header to a 301 redirect will discourage spiders from indexing it - 301 is a permanent move. I may be wrong.

    Code:
    header( "HTTP/1.1 301 Moved Permanently" ); 
    header( "Location: ..." );

    Comment

    • jeddiki
      Contributor
      • Jan 2009
      • 290

      #3
      Thanks for your reply,

      I should mention that with the
      suggestions above, the code is being loaded
      from a .htaccess re-write command.

      So the rewrite is like this:
      RewriteRule ^[\.-a-z]+/bonuses-K([0-9]+)\.html$ ad_linker.php?a =$1 [NC,QSA,L]

      and then the ad_linker.php?a =$1 code
      will look like this:

      Code:
      require_once("my_functions.php");
      
      $today = date("U");
      
      if(isset($_GET["a"])){	 	 			    
      	$N_ad_id = safe_sql($_GET["a"]);
      
      	  $sql = "SELECT ad_link FROM adverts WHERE advert_id = $N_ad_id";
           $result = mysql_query($sql)	or die("could not execute find PRODUCTS query". mysql_error());  
      		 $num = mysql_num_rows($result);
      
      		 if ($num == 0 ) {
        	   echo "There an ERROR in locating this product.";
      	   }  // endif	
      		 else{       
      		    $row = mysql_fetch_assoc($result);
      				$N_ad_link = "http://".$row["ad_link"];
      	
      	 // update database
      	   $sql = "UPDATE adverts SET click_cnt = click_cnt+1 WHERE advert_id = $N_ad_id";
      		 mysql_query($sql) or die("could not execute adverts update query". mysql_error());
      
      echo "<html>
      <head>
      <title>Temp Page</title>
      <meta name=\"allow-search\" content=\"no\">
      <meta name=\"robots\" content=\"all, noindex, nofollow\">
      <meta http-equiv ='refresh' content = '0;url = $N_ad_link'>
      </head>
      <body>
      </body>
      </html>";  
      	 exit();
      	 } // end else
      } // endif
      echo "No Link data !! - please inform admin";
      
      ?>
      Do you see any problems with this ?

      ( I don't think headers sent earlier will be a problem as this is a new page,
      unless I misunderstood )

      Thanks
      Last edited by Markus; Mar 15 '09, 12:06 PM. Reason: Changed [php] to [code]

      Comment

      • jeddiki
        Contributor
        • Jan 2009
        • 290

        #4
        Hi Marcus ( or anyone else)

        What did you think of this as a solution ?

        Have I misunderstood anything ?
        Should it work OK ?

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by jeddiki
          Hi Marcus ( or anyone else)

          What did you think of this as a solution ?

          Have I misunderstood anything ?
          Should it work OK ?
          Sure, if it works for you, then ok. But it's more code that what is necessary; the page loading the html isn't needed, and will just make it a tad slower. I'm pretty sure my post above would prevent spiders from following the redirect.

          Comment

          Working...