Web download tracking
December 1, 2004 5:22 PM   Subscribe

Web download tracking: I've got a bunch of (totally legit etc etc) binary files available for download. I have them linked from a server I run to a server I have space on but don't run. (The html is on my own server, the binaries are on the other one.) I want to track downloads of the binaries, but I can't get at the access logs for their server. What can I do on my server to track 'click throughs' from the html page to the binaries? I'd like it to be completely transparent to the client: they can wget, right click download etc etc but I just want to know when they initiate a connection to download from the binaries' server.

The kind of thing I'm looking for is a way to have apache log the request locally first and then rewrite the URI to point to the other server and redirect it immediately. I can change apache on my server to my bidding, any ideas?
posted by neustile to Education (6 answers total)
Best answer: The best way to do it is with a Redirect in Apache. The urls will indicate your site but will instantly switch to the other site when clicked or fetched. And they will show up in your access logs as a 301 or 302 return code (rather than a normal 200 one).

The redirect line looks like this and goes in the .htaccess file:

Redirect permanent / http://www.example.com/

Change the paths as needed. Since the files were never on this server, just create a new directory that you'll pretend they're in, and then put the .htaccess file in there. You can then use relative links to the files in that directory. Replace the full example URL with the full path to the matching directory on the other server.

(I only know this because I do it on my site to put some of my photos on another server that has more space. Example -- check the URL before you click.)
posted by smackfu at 5:43 PM on December 1, 2004

If you have PHP support, you can do something like

header("HTTP/1.1 302 Moved Temporarily");
header("Location: http://www.otherserver.com/file.exe");
header("Connection: close");
posted by zelphi at 5:44 PM on December 1, 2004

Response by poster: smackfu, that is a great and awesome answer that worked perfectly! And here I was looking up how to use mod_rewrite. I thank you many, many times.
posted by neustile at 6:18 PM on December 1, 2004

Hmm, that's way neater, but if you wanted anything more robust, you can just put all the binaries in a folder (or folders), capture all requests to that folder with mod_rewrite, send them to a page that transparently bounces them to their request (which you allow through a rewrite condition) after logging whatever info you like.
posted by yerfatma at 6:37 PM on December 1, 2004

I'm interested in doing the same sort of thing, but I'm using IIS with ASP (for a variety of reasons, I'm stuck with Microsoft stuff at this point...)

Any suggestions?
posted by JeffL at 6:49 PM on December 1, 2004

It's actually easier in IIS. Go into the management tool for IIS, and choose to create a new virtual directory under your desired web site. Give it the directory name you want, and point it at any of your local directories for now (it doesn't matter where). Then open the properties on the virtual directory you create, choose the Virtual Directory tab, and choose the option for "A redirection to a URL".
posted by smackfu at 8:53 PM on December 1, 2004

« Older When did they stop worshiping the Greek gods?   |   Why can some people recall their childhoods and... Newer »
This thread is closed to new comments.