In this article we will explain what is hotlinking and how you can protect your files specially images from it.

The topics we discuss will be:

  • what is hotlinking and why it is bad
  • Protect images from hotlinking using CPanel
  • Prevent hotlinking using htaccess

What is hotlinking and why it is bad

Hotlinking meaning is directly linking to files mostly images from one website to another website by using image URLs. It is an illegal practice if done without taking any explicit permission from the real owner. Hotlinking files is bandwidth theft and could be very harmful to your blog.

If you use images in articles and still didn’t take any measures against hotlinking then you are very much pron to it. People will be able to directly link to your images from within their own articles taking advantage of your hard work.

Protect images from hotlinking using CPanel

You can stop hotlinking directly from your web hosting account CPanel. We are using Hostgator web hosting, look for similar options if you are on another web hosting service.

Login to your CPanel and go to Security > Hotlink Protection.

hotlink protection

Fill all the fields as shown. In URLs to allow access, type your own website address. In the next field, type all the image formats you want to be blocked, comma separated.

In the last field, either enter http://127.0.0.1 or give an image URL address you want to show instead of the image which got hotlinked. Click Submit.

stop hotlinking
This will effectively block all hotlinking requests.
You have to create the image and upload it to your website. Woopoo's Caution

Prevent hotlinking using htaccess

Another way to prevent hotlinking of images is by using htaccess file. You have to create an htaccess file if you are not using one already.

Login to CPanel and then File Manager. Go to root directory normally www or public_html and look for the htaccess file.

hotlinking htaccess
htaccess file starts with a dot and without any extension i.e .htaccess Woopoo's Tip

Sometimes it could be hidden so you have to unhide it otherwise you have to create one
htaccess hidden file
Enter the following code in .htaccess file and save it.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?learningcms.com [NC]
RewriteCond %{HTTP_REFERER} !^http://learningcms.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://learningcms.com/hotlinknotallowed.jpg [NC,R,L]
  • Just for a simple explanation, the third and forth lines are the allowed urls so write your own website domain name here as you don’t want to block yourself.
  • The last line is the image formats you want to block followed by an image url which will be shown whenever someone hotlinked to your images.
  • You have to create one image yourself with text hey buddy! hotlinking is not allowed or write something similar. Upload the image to to your website.

This htaccess code will restrict hotlinking of images and works with any type of websites and blogs including WordPress.

Just as a final note, hotlinking protection is a must for all bloggers as images are always a vital asset of any blog and protecting them from hotlinking should be done as soon as possible.

If you find it article useful, don’t forget to share and if you still have any questions, do let us know by using the comments section below.

Gimme a Share pleeeaase!

Pin It on Pinterest

Share This