Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is if ($referer != "mysite.com") not a good way to prevent other sites to hard link my images or swf?

Tags:

bandwidth

sometimes i see an image not being served when the browser look at www.somesite.com/some_image.jpg -- it will say you need to look at the image from within a page.

(such as when using google's image search and looking at some results)

so i think their server is using something like

# pseudo code
if ($referer not contain "mywebsite.com") then not serve the image / swf

but this probably is not a good way since HTTP_REFERER is not reliable? so some users will end up not seeing the image or swf when referer info is missing?

like image 896
nonopolarity Avatar asked Dec 22 '22 11:12

nonopolarity


1 Answers

or even better if you have access to using a .htaccess file you could do the following:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg|js|css|cur|png|jpeg)$ - [F]

or if you are wanting them to see a different image then do the following:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.example.com/angryman.gif [R,L]
like image 196
Marc Towler Avatar answered May 09 '23 10:05

Marc Towler