Forum Moderators: phranque

Message Too Old, No Replies

Hot Link protection not working!

         

smagdy

8:03 pm on Aug 13, 2005 (gmt 0)

10+ Year Member



I am trying to stop hotlinking cuz i found some site displaying my pics by linking to my site..

so i found this code:

RewriteEngine On
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com/ [NC
RewriteCond %{HTTP_REFERER}!^$
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ images/nohotlink.jpg [L]

but it brings this error
"500 Internal Server Error"

so why?

i replaced example by my site's name

thanks in advance

jdMorgan

9:07 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lots of problems.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ /images/nohotlink.jpg [L]

You may niot need the first line (Options)
Missing space between "}" and "!"
Closing square bracket on [NC] was missing
Change all broken pipe "¦" characters to solid pipe characters from your keyboard before use; Posting on this board modifies them.

Important: Flush your browser cache before and during testing to prevent unexpected results from browser-cached images.

Jim

Jioffri

12:55 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Would this also work and if so would this be better or worse to use? I am still learning so excuse my question if it seems repetitious or annoying to some of you who are beyond me on the learning curve.

RewriteEngine On
# redirect images
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?anywebsite\.com/ [NC]
RewriteRule \.(gif¦jpe?g?)$ /no.$1 [NC,L]
# block scripts
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?anywebsite\.com/ [NC]
RewriteRule \.(cgi¦pl)$ - [NC,F]

Also, would this not block the cgi based form handler if one were on the site? I think I am having problems with the syntax above as it refers to cgi also. Any feedback would be appreciated.

Jio

Jioffri

1:00 am on Aug 14, 2005 (gmt 0)

10+ Year Member



"Change all broken pipe "¦" characters to solid pipe characters from your keyboard before use; Posting on this board modifies them."

-------------------------------
JD,

Yes, I noticed that when pasting the syntax in my reply that the solid pipe characters were replaced with broken pipe characters after posting. I am aware that only solid pipe characters should be in the syntax but thanks for pointing this website's quirky habit out to all of us.

Jio

jdMorgan

1:51 am on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Also, would this not block the cgi based form handler if one were on the site?

Every site is different. Some prefer to redirect image hotlinkers to a "special" alternate image, and some prefer to simply return a 403-Forbidden. I prefer the latter, since it dispenses with the problem using minimum bandwidth, and makes the hotlinker's site look broken. But this accounts for the various versions of the hotlink-prevention code you find.

You may need to add an exclusion to prevent rewriting your cgi form handler. Something like:


RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com\.com [NC]
RewriteCond %{REQUEST_URI} !^/path_to_your_form_handler\.cgi$
RewriteRule \.(cgi¦pl)$ - [NC,F]

Note that "." is equivlent to "!^$" but it is shorter and requires one less operation (negation is not required).

Jim

Jioffri

2:51 am on Aug 14, 2005 (gmt 0)

10+ Year Member



"RewriteCond %{REQUEST_URI}!^/path_to_your_form_handler\.cgi$"

Jim,

Do you mean URL or URI?

Jio

Jioffri

6:42 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Jim,

I am unable to determine where the path to the vti bin is. What file(s) should I be looking for? Also, I tried various changes and nothing worked. I ended up deleting everything after the Order directives which I combined as suggested. Only then did the form handler work but now I will not have hotlinking protection or anything else. Any advice or links for review?

Jio

jdMorgan

4:00 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



{REQUEST_URI} is a pre-defined server variable.

Frontpage and .htaccess don't play nice together. The following thread discusses the problem and a fix: [webmasterworld.com...]

Jim

Jioffri

12:37 am on Aug 16, 2005 (gmt 0)

10+ Year Member



Thanks for resource info anb for all of your help Jim! I will check it out!

Jim

Jioffri

11:56 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Jim,

The old thread [webmasterworld.com...] provided all of the pertinent information that was helpful with my questions. However, When I use the following syntax:

<Limit GET POST>
Order Deny,Allow
Deny from all
Allow from all
</Limit>

I am still unable to access anything on the site and a 403 is issued. So, my questions are these:

1. The syntax above means that nobody is allowed to GET any pages or POST anything to the site if forms or blogs or bb's are used and a SS engine is used to drive the data? Correct?

2. Should the syntax above be changed to "Allow from all" and remove the "Deny from all" so that way anyone can access the site and all its allowable pages? If I were to do this what would the impact be since it allows me to access the site only when I delete "Deny from all" from the syntax above.

3. Is the correct syntax:

Order Deny,Allow

or is it:

Order Allow,Deny

and does it matter whether "Deny from" or "Allow from" appears first underneath the first line of the directive?

As for all of the other issues I am going through them all one by one to see if I am come up with a workable solution for my needs. It seems as if the older versions of Apache softare are contributing to this? Who knows? However, my server is running Apache/1.3.31 Server at www.example.com Port 80.

I will post again once I find something else that needs addressing.

Jio

jdMorgan

12:47 am on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. The syntax above means that nobody is allowed to GET any pages or POST anything to the site if forms or blogs or bb's are used and a SS engine is used to drive the data? Correct?

No, it means that anybody is allowed to use any method whatsoever to access your server. The code --as written-- does nothing, because it contains "Allow from all", and the Order Deny,Allow directive specifies that Allow from overrides Deny From.

2. Should the syntax above be changed to "Allow from all" and remove the "Deny from all" so that way anyone can access the site and all its allowable pages? If I were to do this what would the impact be since it allows me to access the site only when I delete "Deny from all" from the syntax above.

There would be no change. You're most likely having problems because you forgot to flush your browser cache after changing the code, which interferes with testing.

3. Is the correct syntax:

Order Deny,Allow

or is it:

Order Allow,Deny

If you reverse the Order, then no one will be able to GET or POST. However, regardless of the order, anyone can DELETE, SEARCH, do a PROPFIND, or whatever. I'd suggest that you either don't need a container like <Limit> at all, or that some other container, such as <Files> might be more appropriate.

and does it matter whether "Deny from" or "Allow from" appears first underneath the first line of the directive?

No, this never makes any difference. Multiple Allow from and Deny from directives are allowed, and can be in any order.

Allow me to suggest that the best use of your time might be to go to the Apache site and read the documentation [httpd.apache.org]. This will help you to understand the code, and help to focus your questions. Then please start your own thread and be very specific, as it's impossible to infer from what is posted here exactly what you're trying to do, and what that has to do with the original thread owner's question.

Jim

Jioffri

3:51 am on Aug 17, 2005 (gmt 0)

10+ Year Member



Thanks as always for your help Jim and I appreciate your feedback.

Jio