I want to create one location regex for an endpoint that I currently serve using the following four rules.
location ~* ^/api/(?<version>.*)/(?<service>.*)(/.*/.*/.*/.*)$ {
...
}
location ~* ^/api/(?<version>.*)/(?<service>.*)(/.*/.*/.*)$ {
...
}
location ~* ^/api/(?<version>.*)/(?<service>.*)(/.*/.*)$ {
...
}
location ~* ^/api/(?<version>.*)/(?<service>.*)(/.*)$ {
...
}
That allow an access to my APIs using the following routes:
https://myapp.mydomain.com/api/v1/anyservice/foo
https://myapp.mydomain.com/api/v2/anyservice/foo/bar
https://myapp.mydomain.com/api/v1/anotherservice/foo/bar/thingy
https://myapp.mydomain.com/api/v1/anotherservice/foo/bar/thingy/owl
I have tried many solutions. For example:
location ~* "^/api/(?<version>.*)/(?<service>.*)(/.*){1,4}$" {
...
}
or
location ~* "^/api/(?<version>.*)/(?<service>.*)(/.*)*$" {
...
}
None of the solution I've tried has worked. Any idea ?