How to prevent image hotlinking in WordPress

Tutorials 0 lượt xem

What is Image Hotlinking?

Image Hotlinking is a form of stealing images from a website. Specifically, one site accesses another site’s images directly using the image’s URL.

Let’s say this article is using a profile picture with the following URL: https:///wp-content/uploads/2017/01/image-hotlinking-3.png. As you can see the image is hosted directly on ‘s host (Haw Host ).

Some spam sites link directly to their images using the link on their site. This action of theirs is image hotlinking.

So is hotlinking image harmful?

Image hotlinking is also a way to steal bandwidth on your hosting. Although these days most hosting services have unlimited bandwidth.

But having too many sites consuming your bandwidth is also not a good thing for website performance.

Therefore, you should prevent image hotlinking. In this article, I will give you 2 ways to help you prevent image hotlinking.

How to prevent image hotlinking in WordPress


image hotlinking 3

Use the hotlinking image blocking feature in cPanel

Some hosting providers offer image hotlinking in cPanel. So why don’t we take advantage of this useful feature?

Here I will show you how to enable image hotlinking in Hawk Host’s cPanel.

First you need to login to cPanel. Scroll down to the Security section and click on Hotlink Protection


image hotlinking 1

On the next screen, click the Enable button. That’s it.


image hotlinking 2

Besides, you can update the hotlink protection configuration if you want

URLs to allow access : By default, your host will add all domains in your host as web pages that can access images in your site.

Block direct access for the following extensions : by default the host prevents access to the image. You can also configure it to prevent access to other file formats

Allow direct request : Tick this option if you want to enter the URL of the image in the browser.

Redirect the request to the following URL : Here you can specify an image that you want to display on the site using hotlink technique.

Block Image hotlinking with .htaccess

You open the .htaccess file located in the root directory of your website. If your site is the main domain, the .htaccess will be in public_html. If it’s an add-domain, it’s in a folder with the same name as the domain.

Note : You access the .htaccess file using FTP or File Manager.

Read more :

Instructions for using FTP in WordPress website management

Instructions for using cPanel for newbies

Open the .htaccess file and paste the following line of code:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?your-site.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?your-other-domain.com [NC] RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/g7ptdBB.png [NC,R,L]

Make sure you edit the your-site part to be the name of your site. Your-other-domain is the site you allow hotlinking for. If you only want your website to display images, you can omit this line

At this point, you already know how to prevent image hotlinking.

If you know any other good ways to prevent image hotlinking, please share in the comments section below.

And don’t forget to like or share the article to support

Bài viết liên quan