Using context variables in URL rewrite

I want to use a single value from multiple URL-Parameters in URL Rewrite.

Input URL is like:


that should be rewritten as


I activated context variables for my API on so I get $tyk_context.request_data filled correctly, but how to access the single value for param2 when request_data is “param1:value1;param2:value2”

I tried the following rewrite templates:

customer-groups/$tyk_context.request_data.value2 -> …/endpoint/param1:value1;param2:value2.value2
customer-groups/$tyk_context.request_data[param2] -> …/endpoint/param1:value1;param2:value2.[param2]

You could just use a standard URL rewrite?

URL Pattern: endpoint?{params}
Match: (param2=)(\w+)$
Rewrite: endpoint/$2

Nice sandbox example:

oh, thanks. of cause that will work. Didn´t think about that :slight_smile:

but anyway, would there be a possibility to access a single value from the context variable?

the same question would apply to body transform as I would like to inject a parameter value into the body data

In the URL rewriter - not yet
In the body transform I think you can use dot notation.

yes, in the documentation for body transform it is mentioned, that this is only possible here and not for URL rewriting

@Martin sorry. I have a question with a regex

Assume url: endpoint?{params}
on calling the API i need my url to be like:“mynae”&id=“myid”

Then i need to rewrite to: http://api/operation?name=$2&id=$3
How will the regex look like

Hello @Corrensa,

If you know that the URL params are always be in this order ?name=“mynae”&id=“myid” you can do the following regex name="(\w+)"&id="(\w+)" the rewrite should then be http://api/operation?name=$1&id=$2

If the URL params are not going to always be in that order then you’ll need a more complex regex to handle it.