Forum Moderators: phranque

Message Too Old, No Replies

Prevent Image Linking

         

jenniegbg

12:24 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



I have read about preventing linking from other sites..whit help of .htaccess.. But how do i prevent linking from specifik site?

Jennie

[edited by: tedster at 5:32 pm (utc) on Feb. 5, 2005]
[edit reason] remove email address [/edit]

syktek

1:24 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



if you have mod_rewrite on your server you can add this to your .htaccess file in the root of your server or in a specific dir.

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ - [F]

Be sure to replace "mydomain.com" with your own. The above code causes a broken image to be displayed when its hot linked.

jenniegbg

2:28 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



This line of codes prevent all to link my pics..... But i need to prevent Specific site from linking my pics... I want to prevent only one site to link my pics?

Jennie

[edited by: tedster at 5:33 pm (utc) on Feb. 5, 2005]

jdMorgan

7:51 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jennie,

Welcome to WebmasterWorld!

> i need to prevent Specific site from linking my pics.


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

This will work most of the time, but it depends on the HTTP_REFERER being present in the request. For more info, take a look through the other recent posts dealing with hotlinking.

Also, replace the broken pipe "¦" character with a solid pipe before use.

Jim

jenniegbg

12:24 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



well okej this will be in .htaccess file?

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.badsite.com [NC]
RewriteCond %{HTTP_REFERER} ^http://badsite.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

But i have 8 .htaccess files... which one? All of them?

jdMorgan

4:43 pm on Feb 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But i have 8 .htaccess files... which one? All of them?

That depends on whether you have eight sites or eight subdirectories.

The simplest way is to put the code in the .htaccess file of the directory above the subdirectories where the images are stored. Or you can put a copy of the code in each image subdirectory, if the site has a lot of non-image content; this will slightly improve server efficiency.

An .htaccess file will affect requests for all resources in the same directory as the .htaccess file, and all subdirectories of that directory.

Jim

jenniegbg

8:21 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



Hi

so if my images are in
www.mysite.com/images/jpg/

then .htaccess file shoud
www.mysite.com/images/jpg/.htaccess

and in .htaccess is this

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.badsite.com [NC]
RewriteCond %{HTTP_REFERER} ^http://badsite.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

I just want to confirm this...

Then the site (badsite.com will be prevented of using my pics..?

jdMorgan

10:05 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Leave the code the way it was. This will cover either www.badsite.com or badsite.com. The extra characters are required -- they are regular-expressions operators. For more info, see the links in our forum charter.

Place this in www.mysite.com/images/jpg/.htaccess


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

Change the broken pipe "¦" character to a solid pipe before trying to use this code.

Flush your browser cache before testing any change to your access control code; Images fetched from local browser caches cannot be affected by server-side access controls until those cached entries expire.

Jim

jenniegbg

12:29 am on Feb 8, 2005 (gmt 0)

10+ Year Member



Well tnx U rely helped a lot.... i will try this now as it is ...

i just wonder u mean broken pipe between gif and jpg?

becose i need to prevent only jpg pics so i can remove broken pipe and gif?

br/jennie

jenniegbg

11:18 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



OOOOOhhhh it works... thank you very mutch....
One more thing ..... There is a line of code to put there...

So my site returns a other picture.... :D

What is that line of code?

jenniegbg

11:31 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



Nooo need i did a google serach and found some other thread on this board :D

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.org [NC]
RewriteRule \.(gif¦jpg)$ [mysite.com...] [R,L]

jenniegbg

7:20 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Sorry for bothering you ones more... But how do i write when i want to prevenr for example 3 sites? --.....

Tnx for all others replyes :D

jdMorgan

9:27 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be careful copying code from other sites and other threads... Especially until you understand what it's doing. The code you copied does a redirect, which is unneccessary and depends on the client's cooperation.

The following is much more efficient, and blocks three sites:


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite2\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite3\.net [NC]
RewriteRule \.(gif¦jpg)$ /FO.jpg [L]

1) Change the broken pipe "¦" to a solid pipe.
2) No [OR] on the final RewriteCond.
3) I suggest making "FO.jpg" a simple "This image stolen from mysite.com" message. Remember that it will be seen by the public, none of whom are responsible for doing the hotlinking. Embarrass the other webmaster, but don't make the visitors mad...

Jim