How to Stop Image Hotlinking Using .htaccess File


What exactly is Image hotlinking and Bandwidth theft? Have you ever noticed  image theft from your website by directly taking the URL and showing on their sites without your permission? I will state an example here so that you will better understand this concept. Someone like an image on your website and wish to use it on their site.

If  they are using the full URL of the image on their website, they are using your bandwidth for that specific image. This means that each time someone looks their site, that image is downloaded from yours.  If someone is directly linking to the image or video files of your website, it can be termed as bandwidth theft. Hot Link Protection can be enabled so that no one cant steal your bandwidth anymore.

If you are allowed to download an image,  the right  procedure is to download and then re-upload it on your site (if you are not permitted to do so, it is also stealing! ). But never  link the image directly, it is hotlinking. The question is how do you protect your site from hotlinking?

How to prevent image hotlinking?

You can prevent bandwidth theft by  placing a file named .htaccess in your root (main) directory of the site. The file is kept hidden in the root directory and hence if you wish to create this file, you may initially need to make a notepad file with extension as .txt. Now you can upload it to your server and rename the “htaccess.txt” file to (.htaccess). If you cannot access the server files, you may contact your web host provider to access your directory and change your .htaccess file.

For example, consider your site as “”. Place the below code in your .htaccess file to prevent top hotlinking of your images and show a replacement image called qw7.gif from a host.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ [L]

If you wish to stop hotlinking only from specific domains only, such as, and any other web site to hotlink your images), you may consider the below code.

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blogspot\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?livejournal\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ [L]

Hotlinking can have an array of unpredicted consequences and hence it is often recommended to stop it.

You are free to add as many different domains as you wish. Make sure that each RewriteCond line  end with the [NC,OR] code. Using .htaccess file is the most effective way to stop image hotlinking from your website.