Forum Moderators: phranque

Message Too Old, No Replies

rewrite rule to store referer information

how do I save proxy or leecher referer?

         

olaf

10:52 pm on Dec 6, 2006 (gmt 0)

10+ Year Member



Hello,

I want to store http_referer information about file request from other servers then mine (leecher)

just in case someone is using showing this file on his server (www.leechserver.com)

[3]http://www.domain.com/cgi-bin/nph-proxy.cgi/000110A/http/www.ibm.com/logo.gif[/3]

currently I used this rewrite rule:

[3]
RewriteCond %{REQUEST_URI} ^/cgi-bin/nph-proxy
RewriteCond %{SCRIPT_NAME} (jpg夙if如ng存wf圭ss)$
RewriteRule .* http://www.domain.com/img.php?image={REQUEST_URI}
[/3]

the file img.php is used to store the http_referer information.

I need to say the the folder "cgi-bin" is NOT above the root, any idea whats wrong?

jd01

11:05 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not just set the file to store information rather than using .htaccess?

I am assuming since it is a (dot) .cgi question the file is dynamic. If this is the case, you could probably store information and 'block' bad requests 'on the fly' based on a short series of variables more efficiently than you can rewrite/redirect URLs in some fashion to achieve effectively the same thing.

Justin

Sorry, maybe I am not understanding what you are trying to accomplish. In re-reading your post, it looks like this is what you are doing, but why is the rewrite necesary, and why do you need to say the .cgi is not above the root?

(I'm visual, so I have to understand what you are trying to do to know how I would try to accomplish the same thing.)

olaf

11:19 pm on Dec 6, 2006 (gmt 0)

10+ Year Member



Hi,
thank you for your response.

why not using some code inside the CGI script, actually I'm a PHP programmer and the proxy script is very complex. I'm afraid that solution is not good to me (but that was my first thought too.

Why I'm saying that the "cgi-bin" folder is not above the root? thats because I know situations where this is working fine.

I think the problem is that this cgi-bin directory is a kind of virtual directory.

The only thing I want is to store the http_referer information that I can block the leechers afterwards.

jd01

12:06 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is your .htaccess only works on a per-directory basis, so the request will only 'be seen' by your .htaccess file if your cgi-bin is in the same directory as your .htaccess. You cannot 'go up a level' from within your .htaccess.

If you have access to the httpd.conf file, you should be able to accomplish what you are trying.

I have used the $_SERVER variable coupled with a .txt include located at http://www.myfullcanonicaldomain.com/path-to/the-file.txt to verify server/site authenticity as a work-around to an issue similar to the one you are describing.

Justin

(I know my solution will not work in your specific case, but if you don't have access to the .conf file, finding a work-around might be the only solution, and some times they can be, uh, fun.)

jd01

1:58 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe you are on the same level and do not have permission to make changes/rewrites?

Sorry, I cannot think of another reason your code is not working.
Maybe someone else can see something I am missing.

Justin

olaf

7:38 am on Dec 7, 2006 (gmt 0)

10+ Year Member



Thanks Justin,

yes I have access to the httpd.conf (it's a dedicated server). I will check this tonight.

Olaf

olaf

9:37 pm on Dec 7, 2006 (gmt 0)

10+ Year Member



hello,

I added this to code to the httpd.conf file:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/cgi-bin/nph-proxy\.cgi
RewriteCond %{SCRIPT_NAME} (jpg夙if如ng存wf圭ss)$
RewriteRule .* [mydomain.com...]
</IfModule>

is this the right way to do it (I have several accounts on my server)

jd01

10:21 pm on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I might be inclined to try something like:

RewriteCond %{HTTP_HOST}%{PATH_INFO} ^www\.example\.com/cgi-bin/nph-proxy\.cgi
RewriteRule \.(jpg夙if如ng存wf圭ss)$ /img.php?image=%{REQUEST_URI} [L]

But I haven't tested this set.

Not sure if you are after an internal (rewrite) or external (redirect) to execute your script.

Make sure you use R=301 if you are redirecting, and 'L' last on rewrites, unless you know you do not need them. (Rule of thumb.)

Justin

olaf

9:58 am on Dec 8, 2006 (gmt 0)

10+ Year Member



I added this rule to an htaccess file

RewriteRule (.*)nph-proxy(.*)(jpg¦gif¦png¦swf¦css)$ [domain.com...] [QSA]

and uploaded the file to the cgi-bin directory
and it works fine now
Thanks!

jd01

6:21 pm on Dec 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it working.
I was just 'throwing darts' hoping to give you an idea.

These are essentially the same, but more efficient:

RewriteRule nph-proxy(.*)(jpg夙if如ng存wf圭ss)$ http://www.example.com/img.php [QSA]

OR

RewriteRule nph-proxy\.cgi[^.]+\.(jpg夙if如ng存wf圭ss)$ http://www.example.com/img.php [QSA]

OR

RewriteRule \.(jpg夙if如ng存wf圭ss)$ http://www.example.com/img.php [QSA]

Just some other ideas that might save you some processing.

Justin