url rewriting – nginx forward wildcard urls

Can someone help me with how to set up an nginx forward that does the following:

This is what I have so far. I was going to adapt it but to be honest I can’t get off the ground

location ~* ^/pdf/(.*)$ {
      rewrite ^/pdf/(\d+)*$ /pdf.php;
 }

    

I would like it to :

  • match any urls that are the in the format
    • https://example.com/pdf/My-Old-Man
    • or https://example.com/pdf/My-Old-Man/
    • https://example.com/pdf/Big-Hamster
    • or https://example.com/pdf/Big-Hamster/
      and forward them to pdf.php
  • not match calls to pdf.php directly
  • forward the part /My-Old-Man such that I can read it in my php as part of the ‘$_SERVER[‘QUERY_STRING’]’ later on (to query a db)
  • disallow anything https://example.com/pdf/My-Old-Man/bobchips

I know this is asking a lot, but I think this sort of thing is really useful and I can’t see anyone doing it on the internet.

Read more here: Source link