Enable Hotlink protection using .htaccess file

What is “Hotlink” or “bandwidth theft”?

Hotlink is direct linking of a website’s files (images, videos etc). For example, If someone wants to display your website image on their site, and if they use the image’s URL to display it , then it is called Hot linking. Here, your image is directly linked on other site.

What happens with Hot linking?

When your site files are directly linked on other sites, they will be called from your server. This will increase the usage of your server bandwidth. It is also called as “Bandwidth theft”. You will see high usage of server bandwidth without much site traffic.

Prevent Hot linking using .htaccess file

You can prevent hot linking or bandwidth theft by adding a simple basic code in .htaccess file. This prevents other sites from displaying your directly linked files or images.

Copy below code and paste it at the end of your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursitename.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google\. [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]


  1. Replace “yoursitename.com” with your site name in above code
  2. 4th line in above code whitelists all google’s country specific URLs. If you enter google.com, you may block the images on all google’s country specific domains Ex: Google.ca, Google.ac, Google.co.in etc.
  3. I have added google, yahoo, bing to the code. Add if you need to add any other.
  4. last line is the list of the file types that cannot be hot linked