markb
markb

Reputation: 1305

Stop indexing certain images

So I have a robots.txt file which contains:

User-agent: Googlebot-Image
Disallow: /

At most, it stops the indexing of a lot of images. However, I also have affiliate images that when you search come up in results in Google (and assumably other search engines too).

I was wondering if it was possible (I've searched with no results) to add a rel="noindex" to images, or equivalent.

The affiliate images are served through a PHP loop, so I was looking for a one line fix if possible, as well as knowing that I wouldn't have to manually add the code each time :)

Upvotes: 2

Views: 4318

Answers (3)

John Conde
John Conde

Reputation: 219924

Since the images are being served via PHP you can easily tell Google not to index them by sending a HTTP header designed specifically for this purpose.

Just put this line before your image output:

header("X-robots-tag: noindex");

Upvotes: 2

Ares
Ares

Reputation: 5903

You cannot tell google, or any search engine for that matter, not to index images that are not coming from your domain.

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

add images that you dont want to be indexed in some folder, like dontindex, then add:

User-agent: Googlebot-Image
Disallow: /dontindex/

This tells the robots not to include the contents in the dontindex directory. If you keep your images in a different directory, change that to whatever the name of the directory is where you keep your images.

So next time Google crawls your site, it sees this directive and drops your image from search results. See: Prevent Images from being Indexed

Upvotes: 2

Related Questions