This is my folder structure:
---- downloads
---- .htaccess
---- index.php
---- download 1
---- download 2
---- download n
.htaccess contents:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^.*index\.php$ [NC]
RewriteCond $1 !^index.php$ [NC]
RewriteRule (.*) index.php?uid=$1 [L]
index.php contents:
<?php
// do stuff
header('Location: http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
?>
I'm redirecting every request for a download, e.g. downloads/download 1 to index.php where I do something and then redirect to the original file, downloads/download 1.
This works out fine except that I don't know how to NOT apply the rewrite rule in .htaccess when the HTTP referrer is index.php.
I tried with RewriteCond %{HTTP_REFERER} !^.*index\.php$ [NC] but it keeps looping.