I'd like to use an htaccess file to redirect all media requests to a PHP file. The PHP file will analyse the filenames to see if they are in a list and if not, it will load the media files regularly.

I'd like to ensure everything about this works normally. As in, caching won't break. Do I need to do anything special with the PHP file?