location /search/ { if ($request_uri ~ "/search/([^?]+)") { set $q $1; rewrite . /search?q=$q break; } proxy_pass http://www.new.com; }