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.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)? [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 to your website's URL, and you can add as many websites as you want. You can see "," 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.


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:

Was this article helpful?