How To Allow Some Sites For Hotlinking Images(If You Prevent Hotlinking by .htaccess)

Previously I wrote an article on Blogtechnika that How To Prevent Hotlinking Inside Your WordPress Blog. I got several response from readers. Thanks to Jaspal and Pascal who notified me about those images which are not displayed on Google feed reader.

I want to tell the reason behind this. The reason was that I prevent all the sites from hotlinking Blogtechnika’s image and unfortunately Google reader also don’t get permission to hotlink my image. That’s why images were not displayed in Google reader.


Also one of my reader Pascal asked an interesting question in the previous article:

I have two blogs. Example A & B. If my blog A has some images. It has been hot linked by B. If I did what you said here in my A blog , then Images won’t appear in B? Isn’t it? Is there any way give relaxation to my own blogs from this restriction?

Here I am telling a way from which you can stop hotlinking your WordPress blog but allow some sites to hotlink your images.

Paste the following code in .htaccess file and upload it to your root directory.

  1. RewriteEngine on
  2. RewriteCond %{HTTP_REFERER} !^$
  3. RewriteCond %{HTTP_REFERER} !^http(s)?://( [NC]
  4. RewriteCond %{HTTP_REFERER} !^http(s)?://( [NC]
  5. RewriteRule \.(jpg|jpeg|png|gif)$ [NC,R,L]

Line 3 & 4 are responsible for site allowed to link your images. You can add more site according to your choice.

You can overwrite the previous code with this code. Or you can make a new .htaccess file if you don’t have .htaccess file in a root folder.

This is the main problem for  images to not displayed on Google feed reader. But now I added more site such as, and few social media and news aggregator sites to allow hotlinking.

Note: Always allow your own websites for hotlinking. If you have two or more than two websites on the same server , add all the link of your websites in code so that your website may not affect by .htaccess method.

If you still met any problem, kindly discuss it in comment section. I will surely reply to your queries.

Update: Don’t add this line i.e. feed url of your blog (RewriteCond %{HTTP_REFERER} !^ [NC]) in place of links otherwise your blog will experience 500 internal server error. I don’t know the exact reason for this but it may be because of endless loop inside the server.

Subscribe to Blogtechnika for free updates. Follow me on Twitter @techim.

5 Responses

  1. This article closes all my questions and thanks for the quick update..
    .-= Rajesh Kanuri´s last blog ..WordPress 2.9 Beta 2 is Available: Download & Explore =-.

Leave a Reply

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