Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding noindex header to php redirect file

I have a simple php redirect script (link.php) that I use to keep track of our affiliate links. (Example: http://www.example.net/link.php?id=1 will bring you to http://www.product1url.com)

I've noticed that Google is indexing http://www.example.net/link.php?id=1. I have link.php set to noindex in Robots.txt but that's not stopping the indexing. So I want to add a "noindex", "nofollow" header to each URL itself.

Here's the script I have:

<?php

    $path = array(

    '1' => 'http://www.producturl1.com',
    '2' => 'http://www.producturl2.com',
    );

    if (array_key_exists($_GET['id'], $path))
     header('Location: ' . $path[$_GET['id']]);

 ?>

How do I modify this to include: "X-Robots-Tag: noindex, nofollow"? Is this possible?

like image 705
zoe739 Avatar asked Jun 18 '26 16:06

zoe739


1 Answers

You can output as many headers as you want as long as they are in the code before any potential output is generated. Generally the redirect should be last, though.

Simply add your header("X-Robots-Tag: noindex, nofollow", true); before the $path = array( line.

Also, I know this wasn't in the question, but you will want to update your sitemap.xml file for the index.php URI set to today's date. This will often lead to faster deindexing. (see: https://www.reddit.com/r/bigseo/comments/5nbh3n/google_ignoring_my_noindex_tags/ the post from johnmu, who is (was?) a Google employee.)

like image 112
Wige Avatar answered Jun 20 '26 05:06

Wige



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!