Prevent Image Hotlinking in Easy Steps

How to prevent image Hotlinking?

If you are going to allow image hotlinking, anyone can use your images on their websites and your bandwidth will be utilized. This is a common problem with so many website owners.

Creating a .htaccess file on your TNP HOST web server
  • Go to File Manager in your TNP HOST cPanel
  • Click Create File
Add the following code to your .htaccess file in your TNP HOST web Server

By entering the following code in your .htaccess file , you can prevent Hotlinking on your server :
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]
RewriteRule \.(gif|jpg)$ [R,L]

** Make sure to change to your own URL you used while you hosted your website on TNP HOST server.

Block only Specific Domain

The following code will help you block only specific domain on TNP HOST web Server

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?example\.com(/.*)*$ [NC,OR]
RewriteRule \.(jpeg|JPEG|jpe|JPE|jpg|JPG|gif|GIF|png|PNG|mng|MNG)$ – [F]

Allow only Specific Domain

The following code only allows specific sites to load content. For example, the site has all of the content. The following code allows only and to load the content. All other sites attempting to request any resource fail to load the resource, but no errors are thrown:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dreamhost\.com(/.*)*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com(/.*)*$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpeg|gif|png)$ – [F]

In addition, since a user agent may not always specify an HTTP_REFERER value, the RewriteCond %{HTTP_REFERER} !^$ line allows the request to go through if the HTTP_REFERER value consists of a blank string.

Using an .htaccess file on your website is unlikely to cause any problems. However, it is possible for errors to occur if the rules entered into the file are incorrect which may cause your site to suddenly display a 500 error. If something like this occurs, you can comment out the rules/lines you have just added by placing a ‘#’ in front of each line. Repeat this until you find the line causing the error.

If you having any difficulties following this article, please comment below. TNP HOST support representative will get back to you with best possible solution. To Buy hosting for your website, click here

Was this post helpful?

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.