1

how to prevent load my website images on special sites

because many websites hotlink my website images How to Detect and Stop Image Hotlinking on my Website thanks

0
0

The correct way would probably be to configure a ".htaccess" file to redirect every referer URL being different than your website to a "No hotlinking allowed" image or to a 403 page.

So globally, configure a .htaccess in your image directory so that if "REFERER" isn't "mywebsite.com", then you redirect to a "403 file" or a "no hotlinking allowed" image.

I let you check those websites about .htaccess (sorry, can't post more than 2 links ...) :

  • tltech.com/info/referrer-htaccess/
  • www.htaccess-guide.com/deny-visitors-by-referrer/
  • stackoverflow.com/questions/13106299/redirect-using-htaccess-based-on-referrer

Another solution, if you want to make it more flexible (for images, videos, posts, some data ...) you could change your URLs to direct to a special PHP file that will return the desired content according to GET elements.

E.g. : a file (let's say "imgsrc.php") reads the referer ("HTTP_REFERER") and GET data to identify what picture to retrieve (e.g. .../imgsrc.php?name=pic1234). If the referrer is the same as your domain name, then it outputs the image. If it's not the same, then you output the default "no hotlinking allowed" image or the 403 HTTP CODE like so : header('HTTP/1.1 403 Forbidden'); die();

You would then have in your HTML files : <img sc="/imgsrc.php?name=pic1234"> instead of the usual <img sc="/path/to/src/pic1234.png">


Those may not be the best ways to achieve what you want, but they are what I would use.

I advise you to check tutorials on Google about how to prevent hotlinking. Probably better explained and accurate than my solutions !

Not the answer you're looking for? Browse other questions tagged or ask your own question.