title: NGINX rewrite rule for dynamic URL
body: <p>I was wondering about how to write a correct rewrite for nginx as it fails everytime.</p>
  
  <p>I have a page that can either be visited without any action (<a href="http://foo.bar/praemienshop/" rel="nofollow noreferrer">http://foo.bar/praemienshop/</a>) or with a parameter inside the url which then triggers an action (<a href="http://foo.bar/praemienshop/1" rel="nofollow noreferrer">http://foo.bar/praemienshop/1</a>). The parameter should always be numeric. If possible, the ending slash should be optional if no parameter is given.
  This is what I tryed:</p>
  
  <pre><code>location /praemienshop {
          rewrite ^/praemienshop(|/)([0-9]+/.*?)?$ /index.php?url=praemienshop&amp;item=$1;
  }
  </code></pre>
  
  <p>Iam able to open foo.bar/praemienshop but everytime I open foo.bar/praemienshop/3 (or any other numeric value) it just throws a 404 not found.</p>
  
  <p>I'm neither really good at writing regexp nor do I really understand completely how rewriting works in nginx. I had it working in IIS, but importing it to nginx is quite hard somehow.</p>
  
  <p>Thanks for any help.</p>