Forum Moderators: phranque

Message Too Old, No Replies

need help with rewrite

         

redhat71

7:24 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



i'm using a counter (pphlogger) which offers a function to count file download:

===============================================
download counter - dlcount.php

There's a download counter integrated in PowerPhlogger. In order to use it you just need to modify your links:

use this syntax, if yourfile.zip is located relative to your primary URL (the first URL you set in your
userprofile):

<a href="[path_to_pphlogger]/dlcount.php?id=[username]&url=/yourfile.zip">yourfile.zip</a>

If the file is located anywhere else, use an absolute path:

<a href="[path_to_pphlogger]/dlcount.php?id=[username]&url=http://www.somewhereelse.com/yourfile.zip">yourfile.zip</a>

=============================================

the problem is that i can't make use of it by editing the "href" part manually, cause i am using autoindex to layout files

so, i am thinking of using the rewrite fuction to do that but hours of reading doc and dealing with rules, i'm totally lost

any help will be appreciated

jdMorgan

11:54 pm on Apr 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



redhat71,

rewrite yourfile.zip to [path_to_pphlogger]/dlcount.php?id=[username]&url=/yourfile.zip:


RewriteRule ^yourfile\.zip$ /[path_to_pphlogger]/dlcount.php?id=[username]&url=/yourfile.zip [L]

I don't know where you want to get the username from, so there may still be some unfinished work here. You may also need to rename the "real" yourfile.zip to prevent recursion, and change the filename on the right sight (only) of the above rule to match.

The above is intended for use in .htaccess; For use in httpd.conf, add a leading slash to the RewriteRule pattern, i.e. ^/yourfile\.zip

See this Introduction to mod_rewrite [webmasterworld.com].

HTH,
Jim

redhat71

6:41 am on Apr 20, 2003 (gmt 0)

10+ Year Member



sorry, i should make it more clear
i'm think of applying the rule to lots of files, for example, all the *.zip, or all the files in /download

anyway, start with one specific file is a good idea, but i still failed

as you suggested, i tried this:

RewriteRule ^/test/test\.zip$ /pphlogger/dlcount.php?id=redhat71&url=/test/test.zip [L]

127.0.0.1 - - [20/ 4&#26376;/2003:14:36:29 +0800] [redhat71.3322.org/sid#809ddb0][rid#823add0/initial] (3) [per-dir /var/www/html/] strip per-dir prefix: /var/www/html/test/test.zip -> test/test.zip
127.0.0.1 - - [20/ 4&#26376;/2003:14:36:29 +0800] [redhat71.3322.org/sid#809ddb0][rid#823add0/initial] (3) [per-dir /var/www/html/] applying pattern '^/test/test\.zip$' to uri 'test/test.zip'
127.0.0.1 - - [20/ 4&#26376;/2003:14:36:29 +0800] [redhat71.3322.org/sid#809ddb0][rid#823add0/initial] (1) [per-dir /var/www/html/] pass through /var/www/html/test/test.zip

why does the log say "pass through"? thanks

redhat71

6:44 am on Apr 20, 2003 (gmt 0)

10+ Year Member



i forgot to mention, i don't use .htaccess, my rule is put in httpd.conf

redhat71

7:49 pm on Apr 20, 2003 (gmt 0)

10+ Year Member



i got a new thought, the idea could be bad cause it seems always causing a loop

for example:

1, request for [localhost...]
2, apache rewrite it to [localhost...]

3, here comes the problem:

dlcount.php will redirect the client to [localhost...]

now, it goes back to 1

jdMorgan

8:21 pm on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



redhat71,

I'm not sure what the "Pass through" entry in the rewrite log means. Do you get anything in your error log?

From my post above:

You may also need to rename the "real" yourfile.zip to prevent recursion, and change the filename on the right sight (only) of the above rule to match.

Jim

redhat71

4:05 am on Apr 21, 2003 (gmt 0)

10+ Year Member



i don't want to do the "rename" thing, if that's the only way in my case, i might just give up the idea

thanks anyway

jdMorgan

4:30 am on Apr 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



redhat71,

You only have to rename the real yourfile.zip itself. Do not change any links on other pages.
Alternatively, you could move the real yourfile.zip into it's own subdirectory, or change all the old links to it (ugh) to use a different filename/filepath.

The idea is that you must give mod_rewrite something to use to keep the linked-to URL and the final URL distinct, while inserting the script activity between them. This avoids the recursion problem.

HTTP is a stateless protocol and has no "memory," so unique filepaths are probably the easiest way to go.

HTH,
Jim

redhat71

7:03 am on Apr 21, 2003 (gmt 0)

10+ Year Member



i don't have pages ... i use autoindex to lay out files, that's why i am think of using rewrite to do the job

if i have pages, i don't need rewrite, all i need is to modify the links