title: mod_rewrite rule to redirect all requests except for one specific path
body: <p>I'm trying to redirect all requests to my domain to another domain using mod_rewrite in an Apache 2.2 VirtualHost declaration. There is one exception to this -- I'd like all requests  to the <code>/audio</code> path <em>not</em> to be redirected.</p>
  <p>I've written a RewriteCond and RewriteRule to do this but it's not quite right and I can't figure out why. The regular expression contains a negative lookahead for the string &quot;/audio&quot;, but for some reason this isn't matching. Here's the definition:</p>
  <pre><code>RewriteEngine on
  RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.net(?!/audio) [NC]
  RewriteRule ^(.*)$ http://www.newdomain.example [L,R=301]
  </code></pre>
  <p>If I change the RewriteCond to:</p>
  <pre><code>RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.example/(?!audio) [NC]
  </code></pre>
  <p>(i.e. put the forward slash outside of the negative lookahead part) then it works, but the downside of this is that requests to <code>mydomain.example</code> without a trailing slash will not be redirected.</p>
  <h2>Can anyone point out what I'm doing wrong?</h2>
  <p>Here are the rules:</p>
  <pre><code>&lt;VirtualHost *:80&gt;
  ServerAdmin me@mydomain.example
  DocumentRoot &quot;/var/www/mydomain.example/htdocs&quot;
  ServerName www.mydomain.example
  ServerAlias mydomain.example
  
  RewriteEngine on
  RewriteCond {REQUEST_URI} !^/audio
  RewriteRule ^(.*)$ http://www.newdomain.example [L,R=301]
  RewriteLog logs/mod_rewrite_log
  RewriteLogLevel 3
  
  ErrorLog logs/error_log
  CustomLog logs/access_log common
  &lt;/VirtualHost&gt;
  </code></pre>
  <hr />
  <p>Thanks @mercutio -- that makes perfect sense but it still doesn't seem to work.</p>
  <p>Here's what the mod_rewrite log says when I make a request to <code>http://mydomain.example/audio/something.mp3</code>:</p>
  <pre><code>(2) init rewrite engine with requested uri /audio/something.mp3
  (3) applying pattern '^(.*)$' to uri '/audio'
  (2) rewrite '/audio' -&gt; 'http://www.newdomain.example/'
  (2) explicitly forcing redirect with http://www.newdomain.example
  (1) escaping http://www.newdomain.example for redirect
  (1) redirect to http://www.newdomain.example [REDIRECT/301]
  </code></pre>
  <p>Since the REQUEST_URI does start with <code>/audio</code> I would expect the RewriteRule to be ignored.</p>