Can I block other sites from hotlinking to images on my server to preserver bandwidth while still allowing my site to stay discoverable in Google and Bing image search?

1 Answer 1


I am assuming Apache and .htaccess.

From: https://perishablepress.com/creating-the-ultimate-htaccess-anti-hotlinking-strategy/

RewriteEngine on
RewriteCond %{HTTP_REFERER}     !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$           [NC]
RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\. [NC]
RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?google\. [NC]
RewriteCond %{HTTP_REFERER}     !^http?://([^.]+\.)?google\.  [NC]
RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?bing\.   [NC]
RewriteCond %{HTTP_REFERER}     !^http?://([^.]+\.)?bing\.    [NC]
RewriteRule \.(gif|jpe?g?|png)$                             - [F,NC,L]

You will need to change domain in the HTTP_REFERER line to your domain name of course. You may also want to change https to http as well. Also, you can add and or delete file extensions. They do not all have to be images.

This is a trusted site for .htaccess examples should you ever need one.

  • 1
    Hi closetnoc, please see my comment on Mike's answer
    – Knocks X
    Apr 27, 2015 at 6:29
  • 1
    You would also need to specifically allow hot linking from google.com and bing.com because the hot link images in search results. Apr 27, 2015 at 10:50
  • @KnocksX This does allow indexing, however, to be sure that there is no trouble, you can add a referrer per search engine you want. I will add Google and Bing examples.
    – closetnoc
    Apr 27, 2015 at 15:42
  • @KnocksX - I deleted my post because I just saw your question was updated and my rules caused your images to not to be indexed by google. Apr 27, 2015 at 15:57
  • @Mike I understand why you deleted your answer- I would like to say that sometimes another point of view or idea is important even if it does not directly address the question. This is because sometimes there is good advice in taking another tact. I liked your tact in preventing scrapers. It shows that you are thinking from another perspective. Please keep this in mind because sometimes understandings are too one dimensional. BTW- I like your answers!! You are a breath of fresh air! Keep chucking in ideas- Please.
    – closetnoc
    Apr 27, 2015 at 16:24

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.