NGINX Regex location - Starts with X AND does not contain Y
<p>I have the following location config:</p>

<pre><code>location ~ ^/(trucks|cars|planes|system|tools) {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htauth_file;
        proxy_set_header Host "server.lan";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass  http://127.0.0.1:8080$request_uri;
}
</code></pre>

<p>When <em>anyone</em> makes requests to </p>

<blockquote>
  <p>/trucks</p>
</blockquote>

<p>or</p>

<blockquote>
  <p>/cars</p>
</blockquote>

<p>etc, I want them to be authenticated by the basic auth. But when anyone makes requests to</p>

<blockquote>
  <p>/trucks?id=123</p>
</blockquote>

<p>or</p>

<blockquote>
  <p>/cars?id=124</p>
</blockquote>

<p>then I want no authentication, taken care of a lower location block.</p>

<p>I basically dont want the location to match when there is a question mark in the URI. </p>

<p>Is there a way to modify my pasted config so that it does not match when there is a question mark in the URI?</p>