Disable Hotlinking Using .htaccess For WordPress Sites

Hotlinking is the use of an image from one site into a web page belonging to another site. Many bloggers are hotlinked, and have their bandwidth used on another websites. Here’s a solution to protect your WordPress blog from hotlinking.

The first thing to do is to upload an image saying like this one:
Hotlinking Dis-Allowed!

Then, edit the .htaccess file, located in your WordPress root directory (usually named “public_html”). Remember to backup existing .htaccess file before modifying.

Append this code to the existing .htaccess:
1
2
3
4
5
6
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

* If no .htaccess file exists in the root directory, then just create a new one & add the above code in it.