title: How to redirect if user direct access image files with nginx?
body: <p>How do I redirect users if they attempt to direct access any image files by browser only?
  for example I want to redirect from <code>https://example.com/LcOsfv7.jpeg</code> to <code>https://example.com/LcOsfv7</code></p>
  <p>This my nginx conf:</p>
  <pre><code>    location ~* (?&lt;filenum&gt;)*\.(jpeg|jpg|png|webp)$ {
      proxy_pass http://xxx.xxx.xxx.xxx:7492;
      valid_referers example.com;
      if ($invalid_referer = &quot;1&quot;) {
      add_header Cache-Control &quot;no-cache&quot;;
      return 301 https://example.com/$filenum; 
  }
      }
  </code></pre>
  <p>It's not working cause it just redirect to <code>example.com</code> It's not including the filename without file extension</p>