Differentiation between hotlinking and user on the site

Is there a way to distinguish between a site that is a hotlinking image against a user who is actually viewing an image on the site?

<img src="http://example.com/img.jpg"> 

VS

viewing the user directly at http://example.com/img.jpg

+7
source share
2 answers

Your server can generally tell the difference between the user who is looking at the image directly in your domain and the other domain that links your image.

The usual solution is to stop hotlinking and allow direct viewing through .htaccess , allow Apache to display image files in your domain, do not serve image files in other domains.

So, the user can still go directly to your image file ... since your image is in your domain, but your image cannot be used in the image tag in another domain.

So, somewhere in your .htaccess you will have something like:

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

online tools to help you create these .htaccess lines.

Of course, you do not have to be this restrictive, you can allow hotlinking in general, but restrict only hotlinking from "problem domains".

In addition, instead of stopping hotlinking, you can force Apache to serve the image if your choice is for hot linkers and not for the image they request - http://www.yourdomain.com/hotlink.jpg in the following example:

 RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC] RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/hotlink.jpg [R,L] 

.htaccess examples .

+5
source

You can check the referrer, but it is not 100% accurate.

The user can deceive the referrer, and proxies or user settings can deprive him / change.

+2
source

All Articles