title: Negated regex does not work in RewriteRule
body: <p>I'm trying to write rules for mod_rewrite. I need to redirect all requests that begin with &quot;/api/v[0-9.]+/app/[a-z]+/&quot; to app.php and send 400 Bad Request redirect for another requests.</p>
  <p><a href="https://httpd.apache.org/docs/2.4/rewrite/intro.html" rel="nofollow noreferrer">Mod_rewrite documentation</a> says:</p>
  <blockquote>
  <p>In mod_rewrite the ! character can be used before a regular expression
  to negate it. This is, a string will be considered to have matched
  only if it does not match the rest of the expression.</p>
  </blockquote>
  <p>So, I've tried:</p>
  <pre><code>RewriteEngine on
  RewriteBase /
  RewriteRule ^api/v[0-9.]+/app/[a-z]+/ app.php [L]
  RewriteRule !^api/v[0-9.]+/app/[a-z]+/ - [R=400]
  </code></pre>
  <p>If I use this, I get 400 Bad Request for every request.</p>
  <p>I've tried also:</p>
  <pre><code>RewriteRule ^api/v[0-9.]+/app/[a-z]+/ app.php [S=1]
  RewriteRule !^api/v[0-9.]+/app/[a-z]+/ - [R=400]
  </code></pre>
  <p>and</p>
  <pre><code>RewriteRule ^api/v[0-9.]+/app/[a-z]+/ app.php [L]
  RewriteCond %{REQUIEST_URI} !^api/v[0-9.]+/app/[a-z]+/
  RewriteRule !^api/v[0-9.]+/app/[a-z]+/ - [R=400]
  </code></pre>
  <p>I always get 400 Bad Request for every request.</p>
  <p>It looks like the last rule works always. I can't understand why.</p>
  <p>I've tried this:</p>
  <pre><code>RewriteRule ^api/v[0-9.]+/app/[a-z]+/ app.php [L]
  RewriteRule !^a - [R=400]
  </code></pre>
  <p>It works correctly. I get 400 Bad Request for every request that doesn't begin with &quot;a&quot;, redirect to app.php works too. But if I add something to the rule, it doesn't work anymore.</p>
  <pre><code>RewriteRule ^api/v[0-9.]+/app/[a-z]+/ app.php [L]
  RewriteRule !^api - [R=400]
  </code></pre>
  <p>This one doesn't work (400 Bad Request for every request again).</p>
  <p>I can't understand what's the difference between ~^a and ~^api.</p>