scratch that! regex was a little greedy, should look like: ^(.+\.php)(.*?)\? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,168078,168083#msg-168083