Tyk v2.2 Documentation Components

HomeTyk v2.2 Documentation ComponentsRewrite a URL with the API Definition

Rewrite a URL with the API Definition

To rewrite a URL with the API Definition, you must add a new object to the extended_paths section of an API definition:

"url_rewrites": [{
    "path": "match/me",
    "method": "GET",
    "match_pattern": "(w+)/(w+)",
    "rewrite_to": "my/service?value1=$1&value2=$2"

 Configuration components


The path to match, this can contain wildcards, so to match all sub-resources under match/, you could use match/{id}, the wildcard {id} is transformed into a wide regex ((.*)) to ensure that everything possible is captured. This is then discarded. The name of the group is irrelevant, it is only for your reference.


The method to match


This is the actual capture group to generate, this is a pure regex, in this case we are capturing two word groups.


Each capture group you specify is designated with an index, and then made available in the rewrtite_to template, here $n will map against each value found in the capture group, so in the above example, the rewrite will be:

Was this article helpful to you? Yes No