Forum Moderators: phranque

Message Too Old, No Replies

Hot Linking Code

Differences

         

Visit Thailand

3:23 am on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could someone please advise the difference between :

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/3.01
RewriteCond %{HTTP_REFERER}!^http://mydomain\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://www\.mydomain\.com [NC]
RewriteRule .*\.(gif¦jpg¦png¦pdf¦zip¦mp3)$ - [F,NC]

and

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

Is there any apart from the fact the first one blocks more things?

Plus Is there anyway that when someone hotlinks to an image that a default image is sent?

What I would like to do is send a message to the hotlinkers viewers that the image is the property of X and please go to mydomain.com to see the real image.

Visit Thailand

11:58 am on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone have any ideas?

I am now looking at :

RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ [mydomain.com...] [R,L]

Also does anyone know if having FP extensions installed affects this in anyway?

nicebloke

12:07 pm on Feb 7, 2003 (gmt 0)

10+ Year Member



Sure I read somewhere recently that a FP installation does affect mod rewrite.

Visit Thailand

12:38 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks nicebloke do you know how to uninstall them as I do not use them anyhow?

nicebloke

1:08 pm on Feb 7, 2003 (gmt 0)

10+ Year Member



Nope sorry! Know nothing about em.

Visit Thailand

1:47 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK Thanks nicebloke I have now deleted them but it does not seem to have made any difference.

Plus I have one site with very heavy traffic hotlinking to more than 10 of my images.

I just cannot get it right.

jdMorgan

1:54 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Visit Thailand,

Actually, the second version blocks less things - It will not block Mozilla 3.01, which is a common UA for proxies - That "!" ahead of the pattern means "not".

It also will not block access to png, pdf, mp3,and zip files.

The third version in this thread does not take the Mozilla 3.01 UA into consideration, compresses both RewriteConds of version number 2 into one line, and does not issue a 403-Forbidden redirect. Instead, it issues a 302 redirect to an alternative .jpg image.

If you haven't already done so, I strongly recommend that you read this Introduction to mod_rewrite [webmasterworld.com] post, and follow the links in it before using mod_rewrite. It is a very powerful - and therefore dangerous - tool.

(All previous warnings about spaces required preceding "!" in RewriteCond, and the need to replace "¦" pipes with the one from your keyboard apply.)

Jim

Visit Thailand

2:07 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jdMorgan, Thank you very much.

Am I right then in saying that this will work the best and also redirect to X image?

RewriteCond %{HTTP_USER_AGENT}!^Mozilla/3.01
RewriteCond %{HTTP_REFERER}!^http://domain\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://www\.domain\.com [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦png¦pdf¦zip¦mp3)$ [domain.com...] [R,L]

What do you mean by replace "¦" pipes with the one from your keyboard?

jdMorgan

2:28 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



VisitThailand,

I can't tell you which will work best for you because you have not stated your requirements. :o

You cannot redirect a request for a non-image file to an image file - It won't render in the viewer's browser.

You must re-type all "¦" characters in code copied from WebmasterWorld - The above code will work only if the vertical line is solid.

HTH,
Jim

Visit Thailand

2:34 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It has been a long day sorry!

What I want is to stop other websites from embedding my images into their pages from my server.

So really this only affects jpg,gif and bmp.

If they do that I want an image to be served (rather than the red cross) in their webpage such as stophotlinking.jpg

Does any of that make sense?

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/3.01
RewriteCond %{HTTP_REFERER}!^http://domain\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://www\.domain\.com [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp)$ [domain.com...] [R,L]

jdMorgan

2:39 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What subdomains, if any, do you have?

Jim

Visit Thailand

2:41 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No subdomains on this site at all.

jdMorgan

2:57 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



VisitThailand,

Just got off the phone and have to run, so this should get you started:

Create your alternative image in each format your wish to redirect - In this case, jpg, jpe, jpeg, gif, and bmp. In the example below, the replacement image is named "/images/visit_us" plus the file extension. Replace "example.com" below with your domain name, and "123\.45\.67\.89" with your IP address if you do not share an IP address. Otherwise remove that line. Replace all broken vertical pipe "¦" characters with a solid vertical pipe character.

# Block image inclusion outside our domain except Google, AltaVista, Gigablast, Comet Systems, and SearchHippo
# translators and caches, allow blank referers in case legitimate visitor is behind a proxy.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com
RewriteCond %{HTTP_REFERER} !^http://123\.45\.67\.89 # <---------- Your IP address here
RewriteCond %{HTTP_REFERER} !^http://216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\..*www\.example\.com
RewriteCond %{HTTP_REFERER} !^http://babel\.altavista.com/.*www\.example\.org
RewriteCond %{HTTP_REFERER} !^http://216\.243\.113\.1/cgi/
RewriteCond %{HTTP_REFERER} !^http://search.*\.cometsystems\.com/search.*www\.example\.com
RewriteCond %{HTTP_REFERER} !^http://.*searchhippo\.com.*www\.example\.com
RewriteRule \.(jpg¦jpeg?¦gif¦bmp)$ [example.com...] [R=301,L]

I noted one other issue in this thread: .htaccess can mess up FP extensions. I don't know of any case where FP extensions can mess up .htaccess

HTH,
Jim

Visit Thailand

3:13 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you Jim very kind of you will let you know how it goes.

Thanks

Visit Thailand

3:48 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim, I just to want to verify the last line :

RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com
RewriteCond %{HTTP_REFERER}!^http://216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\..*www\.example\.com
RewriteCond %{HTTP_REFERER}!^http://babel\.altavista.com/.*www\.example\.org
RewriteCond %{HTTP_REFERER}!^http://216\.243\.113\.1/cgi/
RewriteCond %{HTTP_REFERER}!^http://search.*\.cometsystems\.com/search.*www\.example\.com
RewriteCond %{HTTP_REFERER}!^http://.*searchhippo\.com.*www\.example\.com
RewriteRule \.(jpg¦jpeg?¦gif¦bmp)$ [example.com...] [R=301,L]

Is that correct should it be RewriteRule \.(jpg¦jpeg?¦gif¦bmp)$ [example.com...] [R=301,L]

or

RewriteRule \.(jpg¦jpeg?¦gif¦bmp)$ [example.com...] [R=301,L]

I have just tried it as above and it does not seem to work on the tester over at htmlbasix.com as the image is still visible.

DaveAtIFG

3:57 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having FP extensions installed will not cause a problem. USING FP extensions in a page (to process a form for example) will conflict with the mod_rewrite module and cause it to act erraticly.

jdMorgan

4:04 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



VisitThailand,

You must follow the instructions I provided exactly. You should not redirect from one filetype to another.

The "$1" in the last line back-references the contents of the parenthesis in the same line. That is, a request for a .jpg file will be redirected to [example.com...] and a request for a .gif file will be redirected to [example.com...] You should create a "hotlink" image file for each file type, so that you do not depend on the visitor's browser's (or an image bot's) capabilities.

The code I provided comes straight from my site, and works as specified.

Jim

Visit Thailand

1:06 am on Feb 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you.

Well it sort of works for me, I guess the server needed some sleep!

What happens though is that when for example hotlinking.com tests the image, the testing page sort of hangs trying to get the image as if going in a loop.

This means that the stophotlinking.jpg which they are supposed to get does not show.

I have checked and double checked the code and it is identical to what you wrote with the pipes changed verified space before! and example swithced to my domain.

Do you see any reason that it seems to be going in a loop rather than redirecting to the other image?

jdMorgan

1:19 am on Feb 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm...

Try this RewriteRule and let us know what happens when you check it:

RewriteRule \.(jpg¦jpeg?¦gif¦bmp)$ /hotlink.$1 [L]

Jim

Visit Thailand

2:02 am on Feb 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim.

First I should explain that all my images are in hundreds of different directories and I am putting this code in the main .htaccess in the root directory.

What happens now is that all the images in the root will not load, it tries to load them but just hangs like before and no image comes up. That is in the browser and in tests.