Map paths based on request parameters

Hi Guys,

I would like to rewrite a url based on a request parameter

e.g.

/test?name=test maps to /test1?name=test
/test?id=123 maps to /test1/123

I maybe missing something in the docs but I don’t see a way to map paths based on request parameters - do I need to use a virtual end point?

You can use the URL Rewritert to capture those:

Path spec: test?name={wc}
Match: test\?name=(.*)
Rewrite: test1?name=$1

Or:

Path spec: test?id={wc}
Match: test\?id=(.*)
Rewrite: test1/$1

(Not I haven’t tested these, but you can check the regexes here

In this case {wc} is just a generic placeholder, it doesn’t mean anything bu acts as a wildcard. In your URL rewrite match you specify what groups to extract fro the inbound URL and then which groups to expose to the rewritten one using the $ notation.

Hi Martin,

Thanks for the quick response.

I tried this and it is not working as expected…

My config is:

Listen path -> /v1/testPath

“url_rewrites”: [
{
“path”: “/test?id={id}”,
“method”: “GET”,
“match_pattern”: “id=(.*)”,
“rewrite_to”: “/get?id=$1”
}
],
“virtual”: [
{
“response_function_name”: “myVirtualHandler”,
“function_source_type”: “blob”,
“function_source_uri”: “”,
“path”: “/test?name={name}”,
“method”: “GET”,
“use_session”: false
}
]

When I make a request to the follow I get a 404 back

GET /v1/testPath/test?id=1 -
GET /v1/testPath/test?name=name -

If I remove the request parameter from the path uri the mapping works as expected but then I cannot map based on the request parameter