Issue with end of string on Regex - method addGet on Routing

Hello everyone!

We have rebuilt our website from scratch using Phalcon but we have an issue with the Router.

In fact due to SEO issues, we had to keep our old URLs and one of them has this pattern : "" (where 'product-name' is a slug of the product's name that we don't check and 1394 is the id).

We coded it like this in our source code:

$this->addGet("/view-([\w]+)-{productId:[\d]+}", ['action' => 'show']);

However when our product has a name with a number isolated like "Awesome 34" whose address is "", a strange thing happens:

  • When we check on regex101, the regex /view-([\w-]+)-([\d]+)/g works perfectly to check that 5730 should be the $productId,

    • On website considers that actually 34 is the $productId and it ignores what is afterward.

    I tried to specify to Phalcon that {productId:[\d]+} was the end of the string using \Z, $ or \z but nothing seems to work.

    Have you ever had this kind of issue ? How do you think I should solve this issue ?

    P.S. : I cannot change the name of our products or the URLs of our website.

Hi @Marwan can you try with this

$this->addGet("/view-{productSlug:[\w]+}-{productId:[\d]+}", ['action' => 'show']); 

Good luck

This one should do the trick: /view-([\w\-]+)-{productId:[\d]+}