Forum Moderators: phranque

Message Too Old, No Replies

redirect loop problem

         

HorckDude

6:42 pm on Aug 7, 2005 (gmt 0)



On a website I (co-)run we have many downloads which I want counted by a download counter I have created. In my root/files/ folder I have for instance a file called 'download.zip', which can be counted and downloaded by my counter if you use the url 'dl.php?file=download.zip'.

That works great, and because I want to make sure downloads are always counted I have rewritten all download urls to the new download counter url.

My .htaccess file (in the root/files/ folder) is this:

====================================
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+).zip dl.php?file=$1.zip [nc]
====================================

Now that works, but what I hadn't thought of was that when the files are redirected to dl.php that file will, besides counting the number of downloads, request the original file. You can see where this is going: it puts you in a loop.

I think I need some kind of command added to the .htaccess file which says it will not redirect if referred to from dl.php

Now I did a lot of searching and found the RewriteCond command which allows or forbids certain websites with an http_referer command, but I have not been able to find out how that would work. I have tried dozens of things but it just won't work. :(

If someone could help me out I would really appreciate it.

jdMorgan

1:55 am on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HorckDude,

Welcome to WebmasterWorld!

Simply change dl.php to "include" or "require" the requested zip file, rather than redirecting the client or using HTTP to GET it. Also, make sure that the MIME-type header written by dl.php is correct for zip files!

httpd.conf and .htaccess are only invoked for HTTP requests, not for internal file reads, so the above approach avoids the unsolvable problem. Also, your original RewriteRule is not a redirect, it is an internal server rewrite (as it should be). It may speed up your server a bit if you use a more specific regex pattern and add the [L] flag to it -- that is, use:


RewriteRule ^([^.]+)\.zip$ dl.php?file=$1.zip [NC,L]

Jim