TheJoe.it Into the (open) source

25Feb/100

Use the file “.htaccess” per bloccare l’hotlinking

broken_link.jpg We continue to talk about ".htaccess”, Today we see how block hotlink to images that reside on our server.

Yesterday we talked about as to prohibit access to our images from external sites (as often happens with forum the amateur sites), that do nothing but increase the use of the band, reducing the resources of our server. In the case of yesterday, the user will see the symbol of missing image, those who try to connect directly to the site I get the error "403 Forbidden”.

Today we want to have fun instead. Would not it be funny if the user instead of seeing the image missing seeing another image that urges him to do not link from our server? This time we will create a file ".htaccess"Directly in the images directory. And 'possible to create more ".htaccess"On a server. If you can create one for each directory. Let's see how it will be our for images:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?thejoe.co.nr [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?ppalinks.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?drupal.org [NC]
RewriteRule \.(jpeg|jpg|gif|png)$ http://example.org/bad.jpg [NC,R,The]

In fact, this code filters the required images based on the site that has submitted the request. These lines only affect images with extension jpeg, jpg, gif, the png.

Perhaps it is not clear at all, but with these rules can prohibit '"hotlink"The images to all and sundry, allow it to only a few. Le righe 3, 4 and 5 allow hotlinks only to domains listed. The last line makes the "redirect"Anyone who is not listed on the image"bad.jpg"On the server"example.org”.

Remember, if you are redirecting someone to a different image, must not be located in the images directory of our server, innescheremo o un infinite loop.

Clearly the hotlinking can be applied to any type of file, not only to images. With the following line also we block the zip and mp3 with the code "403 Forbidden”:

RewriteRule \.(jpeg|jpg|gif|png|mp3|zip)$ - [F]

About

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

Filed under: SEO, Tips, Web Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.