How to Disable Image Hotlinking in WordPress

Disable Image Hotlinking in WordPress

Hotlinking occurs when other websites link directly to your server's files, such as images, videos, or other media, and consume your bandwidth without your permission. This can result in increased server load, slower website performance, and higher hosting fees. Fortunately, you can prevent hotlinking in WordPress by configuring the ".htaccess" file. This guide will explain how to disable hotlinking using ".htaccess" file, ensuring the security of your resources from unauthorized access.

1. The .htaccess file is usually located in the root directory of your WordPress installation (the same directory as wp-config.php). Before making any changes, download the .htaccess file to your local machine and keep a backup copy in case you need to revert changes.

2. Open your .htaccess file for editing.

3. Add the below hotlink protection code to your .htaccess file. It will prevent hotlinking by blocking requests for specific image files (jpg, jpeg, png, gif, bmp, webp) if the referer is not from your domain.

# BEGIN Hotlink Protection
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|bmp|webp)$ - [F,NC,L]
# END Hotlink Protection

Notes:

  • It's best to add it either at the top or just before the # BEGIN WordPress section if it exists.
  • Remember to replace “yourdomain.com” with your domain name. Look at the example below:

How to Disable Image Hotlinking in WordPress

Disable Hotlinking for More File Types

If you want to disable hotlinking for more file types, you can simply add the desired file extensions to the RewriteRule regular expression. Here’s how you can modify the .htaccess code given above to include additional file types:

# BEGIN Hotlink Protection
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|bmp|webp|pdf|doc|docx|xls|xlsx|mp3|mp4|avi)$ - [F,NC,L]
# END Hotlink Protection

Note: You can add or remove file types as you like.

4. Finally save your .htaccess file.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
HotWP PRO WordPress Theme

HotWP PRO

If you like HotWP free WordPress Theme, you will love the HotWP premium version. HotWP PRO is easy to use,...

$25.00
FreshWP PRO WordPress Theme

FreshWP PRO

If you like FreshWP free WordPress Theme, you will love the premium version. FreshWP PRO is very user friendly, feature-rich,...

$25.00
CuteWP PRO WordPress Theme

CuteWP PRO

If you like CuteWP free WordPress Theme, you will love the premium version. CuteWP PRO is an improved version of...

$25.00
FlashWP PRO WordPress Theme

FlashWP PRO

If you like FlashWP free WordPress Theme, you will love the premium version. FlashWP PRO is advanced, more user friendly,...

$25.00
GridLane PRO WordPress Theme

GridLane PRO

If you like the free version of GridLane WordPress Theme, you'll love the premium version even more. It will help...

$25.00
MintWP PRO WordPress Theme

MintWP PRO

If you like free version of MintWP WordPress Theme, you will love the premium version. MintWP PRO is an improved...

$25.00
RapidWP PRO WordPress Theme

RapidWP PRO

Did you try RapidWP Free WordPress Theme?, Then you will love the premium version. RapidWP PRO is an improved, more...

$25.00
PowerWP PRO WordPress Theme

PowerWP PRO

If you like PowerWP free WordPress Theme, you will love the premium version. PowerWP PRO is an easy to use,...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 55 WordPress themes.