Do some redirects instead of handling the file with PHP. NGINX is better at this sort of thing than PHP is.