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 →
MagShow PRO WordPress Theme

MagShow PRO

MagShow PRO is the premium version of MagShow free WordPress Theme with more advanced features. MagShow PRO version has 160+...

$25.00
Clean Gallery PRO WordPress Theme

Clean Gallery PRO

If you like Clean Gallery free WordPress Theme, you will love the premium version. Clean Gallery PRO is an elegant,...

$25.00
Clean Grid PRO WordPress Theme

Clean Grid PRO

If you like Clean Grid free WordPress Theme, you will love the premium version. Clean Grid PRO is an elegant,...

$25.00
CleanWP PRO WordPress Theme

CleanWP PRO

If you like CleanWP free WordPress Theme, you will love the CleanWP PRO version. The premium version of CleanWP WordPress...

$25.00
GridHub PRO WordPress Theme

GridHub PRO

If you have tried GridHub Free WordPress Theme, then you will love the premium version. GridHub PRO version has color...

$25.00
MagSoul PRO WordPress Theme

MagSoul PRO

$25.00
GridShow PRO WordPress Theme

GridShow PRO

GridShow PRO WordPress theme is a feature-rich, advanced version of GridShow Free WordPress Theme. GridShow PRO version has color and...

$25.00
GridPal PRO WordPress Theme

GridPal PRO

If you like the GridPal Free WordPress Theme, then you will love the premium version. GridPal PRO version has color...

$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.