Search code examples
php.htaccesshotlinking

Is it possible to tell the difference between hotlinking and regular linking of images using .htaccess?


I think the answer to this is no, but ideally I would like to be able to allow image hotlinking, but redirect regular links. For example, if somebody uses this, it should work as expected:

<img src='http://mysite.com/image.jpg'/>

But if they use this, it would redirect to a different page upon visiting:

<a href='http://mysite.com/image.jpg'>Click Here</a>

I believe $HTTP_REFERER is the same, regardless of the two methods. Is there any other clever way to distinguish between the two?


Solution

  • Many browsers send different Accpet: header in these two situations.

    When requesting resource from <img src="xxx">:

    Accept: */*
    

    When requesting the url in address bar:

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8