Question

since this is the first time someone made me click some referral link i got very curious. Here in the screenshot you will see a masked url which directly goes to some referral link in some other site. Masked Referral Link

The interesting part which got my attention and the reason i clicked the link is that link has a file extension as you will notice. I can think of PHP redirects, .htaccess redirects but couldn't exactly think a solution for filenames masking.

As usually we can parse the url in .htaccess and redirect .zip extensions to a php file to check whether the file is valid filename or a key value for redirect in database (This is a solution too) but i didn't notice any redirect on this link.

Is there any other possible ways for this?

Was it helpful?

Solution

You can redirect any request with .htaccess. For example:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

will redirect all requests to index.php, in which you can check if the user wants file.zip just by looking into $SERVER['REQUEST_URI']. Then serve him the file you want:

$zip = '/path/to/zip/file/outside/the/web/root.zip';

// set correct headers, so the browser identifies the response as a zip file
header('Content-type: application/zip;');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($zip) . ';');
header('Content-Disposition: attachment; filename="whatever.zip";');

// output the file contents
readfile($zip);

OTHER TIPS

Using .htaccess it possible to rewrite ANY request. Link looks like zip-file but request is sent to some php script.

This php file parses requested URI, does what it should do(increments counter, sends money,..) and only after all this stuff gives you file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top