How to Prevent Image Hotlinking for a WordPress Website Using .htaccess

How to Prevent Image Hotlinking for a WordPress Website Using .htaccess

It’s a roller-coaster ride for many WordPress users to handle their websites. Every time they try to cope up with some unknown error, a new term comes up.

Have you heard about image hotlinking? If not, then let me elaborate a little bit, it’s an image theft which also affects the web hosting server.

Everyone is aware of the content theft and how they can secure it, but only a few people understand the concept of image hotlinking and how they can stop it.

You may have read about using DMCA to protect your website’s content. Unfortunately, it doesn’t stop anyone from linking images to your website.

When someone copies your images along with their original URL, they link those images to your web server. It means, whenever someone visits their website, the images get loaded from your web hosting server.

Doesn’t it sound something scary? Well, it can turn into something bizarre, if you don’t take the essential steps.

After a few months, you will realize server overuse and poor page loading time. At such situation, you require to upgrade your web hosting plan to get more server disk space.

The worst thing is that most of the people don’t have any idea about image hotlinking. In this tutorial, you are going to learn to disable image hotlinking using the .htaccess file.

Use the Code Editing Method to Stop Image Hotlinking

You may be wondering if you can accomplish it using a built-in option from cPanel. Well, you can, but it’s necessary to learn all the methods.

Some cheap web hostings still don’t offer access to cPanel for their starter plan, so it’s essential to have an idea about using the .htaccess file.

Now you may be thinking if you don’t have cPanel access, how can you edit the .htaccess file. You may already know that Yoast SEO plugin allows you to edit the robots.txt and .htaccess files from WordPress admin panel.

But, in this tutorial, you’re going to use cPanel.

Let’s start the process.

Step 1

The first step is to log in to your cPanel account and search for the file manager icon under the Files’ section. It’s one of the most commonly used directories because all of your website’s data is available in it.

How to Prevent Image Hotlinking for a WordPress Website Using

Depending on your web hosting, you may find a different design of cPanel, but the file manager remains somewhere you can easily see.

But if you’re using Siteground, Inmotionhosting, Bluehost, or any other reputed web hosting, you don’t need to worry about finding the file manager.

Step 2

Some companies prefer to store the website installation in the “www” folder whereas others prefer to have it in a different folder.

If you’re hosting one website on your server, it’s more likely you can find the data in the public_html/root directory.

How to Prevent Image Hotlinking for a WordPress Website Using

You require to search for the .htaccess file.

Step 3

To add code, you need to edit the .htaccess file by right-clicking>>edit or you can decide to use the Edit option shown on the horizontal navigation menu.

How to Prevent Image Hotlinking for a WordPress Website Using

A popup appears to you to confirm.

Step 4

Add the code before the #End WordPress comment.

/* Prevent image hotlinking in WordPress */RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yoursite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?twitter.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?otherwebsite.com [NC]
RewriteRule .(jpg|jpeg|png|gif)$ - [F]

You may be curious to know what this code does, well, it manages to limit the access to your website’s images to Google, Facebook, Twitter, and your website.

Note: Replace yoursite.com to your website’s URL, and you can add as many websites as you want. You can see “otherwebsite.com,” if you wish, you can completely remove it or replace it with any other website.

If you want to show your images only to your website, remove the second last line.

As I have mentioned, Google has access to images, so don’t worry about search engine indexing. I understand many people might be worried about SEO, well, it’s absolutely perfect.

I Hope You Have Understood the Concept of Image Hotlinking

When it comes to solving any issue for a WordPress website, people might search for a plugin. There are thousands of free plugins in the WordPress repository.

To disable image hotlinking, you can use All In One WP Security & Firewall; it’s one of the most used security plugins with tons of features.

If you’re afraid of editing the .htaccess file, you just use a plugin.

Conclusion

There are different ways to accomplish the same task, and it’s always better to learn those alternatives. You can easily disable image hotlinking using cPanel’s built-in feature, but it doesn’t offer you to have the full control.

You can control access to your website’s images using the .htaccess file. You can see in the code as mentioned above, authorize access to the website you wish.

Check out these top 3 WordPress hosting services:

HostArmada
£1.96 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
Hostinger
£2.35 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
FastComet
£1.41 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
    4.7
  • Support
    5.0
  • Features
    4.8
  • Reliability
    4.5
  • Pricing
    5.0

How to Set Up HTTP 301 Redirection using Plesk.

This article shows you how to set up HTTP 301 redirection using Plesk.
1 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Secure the .htaccess File from Unauthorized Access

This guide will help you add one more security layer to your website by protecti
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Disable PHP Execution to Improve Website's Security Using cPanel

This how-to guide will explain about restricting others from executing any malic
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Stop Image Hotlinking Using cPanel

This how-to guide explains the easiest way to prevent image hotlinking using cPa
3 min read
Angela Olaru
Angela Olaru
Senior Writer & Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top