title: Check if file exists on Nginx using regex
body: <p>I'm trying to translate some htaccess files to Nginx vhost configuration, and i'm having trouble with this:</p>
  
  <pre><code>RewriteCond %{DOCUMENT_ROOT}/img/id_$1_$2 -f
  RewriteRule ^id/(.+)/(.+)$ img/id_$1_$2 [NC,L]
  </code></pre>
  
  <p>As you can see, this condition checks if a file exists using some regex to generate filename dynamically  by the URL entered.</p>
  
  <p>The following nginx directive do the rewrite correctly but doesn't checks for the file bofore:</p>
  
  <pre><code>rewrite ^/id/(.+)/(.+)$ /img/id_$1_$2 break;
  </code></pre>
  
  <p>I just want to do this rewrite if the file really exists, and if not another rewrite will happen.</p>
  
  <p>All ideas may help. Thanks a lot.</p>