title: Excluding directory from regex redirect
body: <p>I wish to redirect all URLs with underscores to their dashed equivalent.</p>
  
  <p>E.g. <code>/nederland/amsterdam/car_rental</code> becomes <code>/nederland/amsterdam/car-rental</code>. For this I'm using the technique described here: <a href="https://stackoverflow.com/questions/15912191/how-to-replace-underscore-to-dash-with-nginx/15934256#15934256">How to replace underscore to dash with Nginx</a>. So my location block is matched to:</p>
  
  <pre><code>location ~ (_) 
  </code></pre>
  
  <p>But I <strong>only</strong> want to do this on URLs <strong>not</strong> in the <code>/admin</code> namespace. To accomplish this I tried combining the regex with a negative lookup: <a href="https://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word/5334825#5334825">Regular expression to match a line that doesn&#39;t contain a word?</a>. The location now matches with:</p>
  
  <pre><code>(?=^(?!\/admin))(?=([^_]*))
  </code></pre>
  
  <p>Rubular reports the string <code>/nederland/amsterdam/car_rental</code> to match the regex, while <code>/admin/stats_dashboard</code> is not matched, just as I want it. However when I apply this rule to the nginx config, the site ends up in redirect loops. Is there anything I've overlooked?</p>
  
  <p>UPDATE: I don't actually want to rewrite anything in the <code>/admin</code> namespace. The underscore-to-dash rewrite should only take place on all URLs <strong>not</strong> in the <code>/admin</code> namespace.</p>