Avoid image hotlinking in WordPress

Image hotlinking is probably the major issue that would lead to over usage our hosting bandwidth. Some scrappers copy images from blogs and post them in forums and other websites and with each page load the allotted bandwidth by hosting provider will go down. Here I am treating this matter in perspective of wordpress blogs. We can avoid image hotlinking in WordPress, mainly by two methods.

Avoid image hotlinking in wordpress

1. With plugins : Hotlink protection plugin for WordPress by Christopher is very useful in this case. The plugin can be used to block an entire URL pattern or a particular image from being hotlinked. The hotlinked image will be shown as below.

As an alternate, we can also use .htaccess file to block  hotlinking in WordPress. But in this case, it would  block images in feeds. Though it can be fixed, I think for a beginner using a plugin would be better.

2. Editing .htaccess file:

This method is pretty difficult when compared with the use of plugins. By using. Htaccess, we can display a custom image(low size ) in place of the each hotlinked image. The first step is to create an .htaccess file or edit the existing one.

If you don’t have any .htaccess fil , create on using notepad and save it extension .htaccess.
Now copy the following code into notepad.

1. RewriteEngine on
2. RewriteCond %{HTTP_REFERER} !^$
3. RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?techknowl.com [NC]
4. RewriteRule .(jpg|jpeg|png|gif)$ https://www.techknowl.com/wp-content/uploads/blogger/272-nohotlink.png [NC,R,L]

All the hotlinked images will be blocked by these default settings. If you want any site to access your images, you can specify them in the 3 and 4 th line. For each site allowed, you have to repeat the step number 3.
5 th line corresponds to the extensions of images to be blocked from hotlinking. Image link shown after $ is nothing but the one shown on infringing websites. After saving the notepad file as .htaccess, upload it to the server. This method can be used to avoid hotlinking in WordPress and all other sites that support Apache, php and MySQL.

This entry was posted in Uncategorized by . Bookmark the permalink.

Leave a Reply

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