title: Regular expression match NGINX url segments from $request_uri variable
body: <p>hoping for some insight here on this redirection process</p>
  
  <p>I am hoping to redirect all URL's EXCEPT ones that match the following.</p>
  
  <p><a href="https://www.something.com/about-us/foo/" rel="nofollow noreferrer">https://www.something.com/about-us/foo/</a> (single page)
  AND
  <a href="https://www.something.com/foo/some-arbitrary-segment/" rel="nofollow noreferrer">https://www.something.com/foo/some-arbitrary-segment/</a> (many pages with this structure)</p>
  
  <p>These are the only urls in the sitemap containing "foo", so I am trying to simply match that.</p>
  
  <p>I first need to check one other conditional variable (I am checking user agents for mobile devices)- all pages except those containing "foo" should redirect to a new domain.</p>
  
  <pre><code>set $mobile_redirect NO;
  
  if (someconditionaluseragentstuff = someconditionaluseragentstuff) {
  set $mobile_redirect YES;
  }
  
  if ($request_uri ~ "foo") {
  set $mobile_redirect NO;
  }
  
  if ($mobile_redirect = YES) {
  rewrite ^ https://www.somemobiledomain.com$request_uri? redirect;
  break;
  }
  </code></pre>