1

I am working on a project where I need to disable specific images from Google indexing, or disable based on their size. I do not have any idea other than adding this code in robots.txt:

User-agent: Googlebot-Image
Disallow: /

As my platform is WordPress, all the images are in Upload folder. So I can't disable based on the folder either.

  • Please edit the question to clarify what you mean by "specific images" (e.g., by filename?). Users would need specific criteria (like size) in order to make suggestions. – dan Dec 12 '15 at 8:45
  • @dan specific images means some random images i need to disable from indexing , may be i can do one thing i can put those image in single category – musthafa Dec 12 '15 at 8:51
  • @musthafa When you put the image in a "single category", does that change the URL for those images? – MrWhite Dec 12 '15 at 11:51
  • No Actual link for the image is in "wp-content/uploads/12/file.jpeg" folder, i just asked is there any way that we can use categories to disable, category link is "domainname.com/category/products_name" – musthafa Dec 12 '15 at 13:07
2

What you can do is generate your images in a programming language with headers to stop indexing and then use some rewriterules to reference that image.

For example. Put this in your .htaccess:

RewriteRule ^(.*)\.jpeg$ /background.php?FILE=$1 [L]

Then create the file background.php with this template:

<?php
$jpeg=imagecreatefromjpeg('/server-path/to/imagefolder/'.$_GET['FILE'].'.jpeg');
imagejpeg($jpeg,NULL,100);
imagedestroy($jpeg);
header('X-Robots-Tag: noindex, noimageindex',true);
header('Content-type: image/jpeg',true);     
exit();
?>

Put .htaccess and background.php in document root folder. Now when you make a request to anything ending in .jpeg from your document root, it will try to find the jpeg file in the /server-path/to/imagefolder folder and then the program adds an extra header to direct search engines not to index that specific file.

If you want something super easy, then divide your images into separate folders and indicate the folder that is not to be indexed in robots.txt.

  • Using this method you could conditionally block the image "based on size". (+1) – MrWhite Dec 13 '15 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.