Optional percent in Rexeg for URL rewriting

96 Views Asked by At

I'm using nginx for an API et my rewriting is in the Vhost and I have an issue with a regex.

My url can be :

  • /products/BR3TMVZ9PNWZ/
  • /products/BR3TMVZ9PNWZ%BPMMFJDVP9NF/
  • /products/BR3TMVZ9PNWZ%BPMMFJDVP9NF%BPNSJSZCRPPF/

The first one works with this :

rewrite /products/([A-Z0-9]+)/ /products.php?ids=$1 last;

I tried a lot of thing with % but I already have a HTTP 400

Thank you

1

There are 1 best solutions below

6
On

Edit :

rewrite "^/products/([A-Z0-9]+)\%{0,1}.*$" /products.php?ids=$1 last;

Should always match the first id BR3TMVZ9PNWZ