In the past, this works perfectly:
#domain1.com
location /files/ {
valid_referers none blocked domain1.com domain2.com domain3.com;
if ($invalid_referer) {
return 403;
}
if (!-e $request_filename) {
rewrite ^(.*)$ https://domain2.com/files/$1 redirect;
}
}
but doesn't work now after I upgraded nginx
I found this, seems if not working with new nginx version: https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
I also found this hack to solve problem: https://agentzh.blogspot.com/2011/03/how-nginx-location-if-works.html
But I don't know how to make it works.
This is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !domain1\.com [NC]
RewriteCond %{HTTP_REFERER} !domain2\.com [NC]
RewriteCond %{HTTP_REFERER} !domain3\.com [NC]
RewriteRule \.rar$ - [F,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://domain2.com/file/$1 [L,R,NC]