0

With the following code I can replace the hotlinked image with another image. However, is it possible to force download the replaced image instead of opening in the browser?

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(subdomain\.)?mydomain.com.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/D5ZIJBq.jpg [NC,R,L]
user1355300
  • 4,867
  • 18
  • 47
  • 71

1 Answers1

2

You can not force download with this rewrite.

Your server must serve this file (for example in http://subdomain.mydomain.com//img/my_fake_image.jpg). Then, modify you rewrite rule and add the following rule (not tested and to adapt)

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(subdomain\.)?mydomain.com.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://subdomain.mydomain.com/img/my_fake_image.jpg [NC,R,L]
<FilesMatch "\.my_fake_image.jpg$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>
Spomky-Labs
  • 15,473
  • 5
  • 40
  • 64
  • 1
    Thanks for the answer, but can you please explain it a bit, what you mean not to adapt? will it harm? Should I place your code below the rewrite rule, will it only force download the imgur.com image? Thanks. – user1355300 Oct 31 '14 at 06:35
  • it does not work, it still displays in the browser, headers mode is enabled in apache, so there is no problem with that. – user1355300 Oct 31 '14 at 07:29