LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Off site image blocking! (https://www.linuxquestions.org/questions/linux-networking-3/off-site-image-blocking-55782/)

brandog 04-19-2003 01:50 AM

Off site image blocking!
 
Is thier a feature or something I could do to block people from linking my images out of my domain, something like geocities or tripod does! I would like to do this for the fact that if somebody posts alot of images being accessed it will take away from my total server bandwith and resources!

jeremy 04-19-2003 09:21 AM

To prevent others from linking to your images put the following in your apache config file:

Code:

Rewriteengine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.trusted.com/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$ - [F]

This basically says if you have a referer that is not blank and not from your site or a site you allow to link images (trusted.com) then rewrite the request to - and give a forbidden response. You could replace the last line with:
Code:

RewriteRule \.(gif|jpg|GIF|JPG)$ http://www.your_domain.com/fake_image.gif [R,L]
and have fake_image.gif be an image saying not to link from your site (or anything you want really).

--jeremy

brandog 04-19-2003 12:06 PM

I have edited and added that code to my httpd.conf file so lets see if it works!

ahhhh you cant post pics here!

brandog 04-19-2003 12:12 PM

It's not working! I restarted my http server aswell! Is there a spacific place I have to insert it!

jeremy 04-19-2003 12:29 PM

First make sure you have mod_rewrite enabled (although apache should have errored on restart if you didn't). You can put the chunk of code in the virtual host statement of the site you want to protect. How are you testing this?

--jeremy

brandog 04-19-2003 12:47 PM

Quote:

Originally posted by jeremy
First make sure you have mod_rewrite enabled (although apache should have errored on restart if you didn't). You can put the chunk of code in the virtual host statement of the site you want to protect. How are you testing this?

--jeremy

I' testing this by adding an image tag to another forum which allows pics to be posted! Mod_rewrite is enabled!

I dont have any virtual hosts set up! Just 1 main site under the /home directory!

jeremy 04-19-2003 01:03 PM

You should just be able to put the rewrite statements at the end of the file then (or almost anywhere outside of another statement). Are you getting any errors? You may want to turn rewrite logging on:

Code:

RewriteLog "/usr/local/apache/logs/rewrite.log"
RewriteLogLevel 9

This will log EVERYTHING so don't leave it that way for production, just so we can figure out what is happeneing. You can adjust the path to suit your setup.

--jeremy

Brando_ou812 10-07-2003 11:03 AM

Finally got this to work a bit but the image shows up as a red X and you right click and it still shows the original linking to the pic! The RewriteRule doesent seem to change the link to the image??

Brando_ou812 10-07-2003 11:58 AM

figured it out the RewriteRule \.(gif|jpg|GIF|JPG)$ http://www.your_domain.com/fake_image.gif [R,L]

Has to have these brackets {} not these ()

http://www.manitobamotorsports.com/m...005%20copy.jpg


All times are GMT -5. The time now is 10:55 AM.