'NextJS redirect slug wildcard
I'd like to redirect URLs that regex match -\d+ to a URL without that string.
This works with the last slug but for the ones prior.
This is my redirect code:
{
destination: `/my-path/:slug*`,
permanent: true,
source: '/my-path/:slug*(-\\d+)'
}
This url: http://localhost/my-path/subdir-one/subdir-two-123
redirects successfully to: http://localhost/my-path/subdir-one/subdir-two
However this url: http://localhost/my-path/subdir-one-3456/subdir-two-123
redirects unsuccessfully to: http://localhost/my-path/subdir-one-3456/subdir-two
I thought the * was to match the entire path and assumed 😬 the regex to be applied on every route.
What am I missing here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
