Problem with NGINX rewrite rules

Hello, I am new to NGINX and am having some issues with the rewrites.

To give some context, in my website right now I have products that can be accessed by their uuid in this way: localhost:8080/products/websiteVersion/?uuid=12345 being 12345 a valid product uuid.

I would like users to be able to access these products by introducing a simpler URL, for example: /products/black-table (the slugs for the products already exist), and then change that in my website to show them the correct page. So, if for example the uuid for the black table is 12345, the user can write localhost:8080/products/black-table and the website will instead open localhost:8080/products/websiteVersion/12345.

At the moment the files for deployment are store in a folder called “out”, and I have this rule in NGINX (this one is working properly at the moment) to use the files in that folder:

rewrite ^/products/(.*)$ /out/products/$1 last;

I wanted to create a second rule to change the name of the product with the correct uuid, like this:

rewrite ^/products/(.)/(.)$ /out/products/$1/?uuid=$2;

The first (*) is supposed to match the website version (since the website will add the website version in the URL when entering products), and the second is supposed to match the name of the product.

Just to clarify, the website version is added in the URL (by the website) and then hidden through javascript as soon as the DOM finishes loading. I don’t know why this version is being added to then hide it inmediately, but that’s the way it is working at the moment.

Seems like I can’t make this work. I have been trying different combinations and orders for these two rules, but nothing worked so far. I would appreciate if someone can give some advice or guidance on this.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.