How to Implement Hotlinking Image Protection Without Affecting Google Image Search

Hotlink protection is implemented to prevent other websites from using your images without your permission via a hyperlink. When an image is hotlinked, it is being loaded from your server, meaning that your server is being used to serve the image to the website that is hotlinking it thereby resulting in your hosting bandwidth theft and increased server load. Normally you would notice your images being hotlinked by low quality site scrapers.

There are a few different ways to protect images from being hotlinked, without impacting Google’s Image Bot’s ability to crawl your website. One method is to add the Googlebot user agent to the list of allowed referrers in your .htaccess file. Here is an example of code that can be added to an .htaccess file to prevent hotlinking, while allowing Googlebot to crawl the site:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_USER_AGENT} !Googlebot
RewriteCond %{HTTP_REFERER} !^https://([^.]+\.)?google\.
RewriteCond %{HTTP_REFERER} !^https://([^.]+\.)?bing\.
RewriteCond %{HTTP_REFERER} !^https://([^.]+\.)?yahoo\.
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]

RewriteRule \.(jpeg|JPEG|jpg|JPG|gif|GIF|png|PNG)$ - [NC,F,L]

In this example, the code blocks all requests for image files (jpg, jpeg, png, gif) from any website that is not yourdomain.com and user agent is not Googlebot, so Googlebot can access the images.

0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *