rewrite rule not working: redirect to php script if file exists

The reason the rewrite rules wont work is because you’ll find that if you look at your .htaccess file, WordPress doesn’t actually load if the file that is being requested is present on-disk.

So if they try to access an image file, because it’s there, on disk, WordPress isn’t loaded and so the rewrite rules have no affect.

You may want to use .htaccess rules. Here is an example of what you could try:

RewriteEngine On
RewriteRule ^custom-media-files/(.+)/screenshot_trade_(.+)_(.+)\.jpg$ /screenshotaccess.php?usrid=$1&fn=$2&i=$3 [L]

I’d also make sure in your screenshotaccess.php that you’re not just using your query/$_GET vars without first checking they’re of the correct format – i.e. you’re santizing your data before you use it.