Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect & hotlinking

         

Go3Team

2:48 am on Dec 29, 2003 (gmt 0)

10+ Year Member



Since I am completly worthless when it comes to coding, I figure I would ask this here.

I have a server that allows uploads, to be downloaded later by others. The index.php handles the downloads, by giving the uploaded file a special name. The file that is uploaded is hidden so that the user cannot determine the exact location. I would like to set up the .htaccess file so that when the index.php is accessed via hotlink, that it will send the file as well as open the normal entrance page, to "pay the bills" I figured it would be easier to code the htaccess file rather than trying to figure out how to do it in the php file. Thanks.

jdMorgan

10:53 am on Dec 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Go3Team,

Welcome to WebmasterWorld [webmasterworld.com]!

> send the file as well as open the normal entrance page

If I understand your question correctly, .htaccess cannot do this. .htaccess runs as part of the process of serving a single requested resource. It runs after the request is received, but before the resource (file) is read from disk. It is only processed once (normally), and therefore, it can't "send" two files.

Having thought about client-side solutions (which won't work because a hot-linking page won't include any client-side code you added) and server-side solutions (such as interposing another script between the request and the actual file), I believe you should reconsider and modify your original php code -- That sounds like the simplest and most logical approach. I'm not really sure what the best way to do it is, but I am sure that .htaccess can't serve two pages for one request.

The standard (and simplest) approach is to simply block downloads if the HTTP_REFERER is non-blank and is not from your domain.

Jim