location = /filehost { rewrite ^ /filehost.php last; } location ^~ /filehost/ { rewrite "^/filehost/([A-Za-z0-9]{6,32}\.[a-z0-9]{1,8})$" /filehost.php?f=$1 last; }