Rewrite to URL with ID param

I’ve got this configuration:

"version_data": {
    "not_versioned": true,
    "versions": {
      "Default": {
        "name": "Default",
        "use_extended_paths": true,
        "extended_paths": {
          "url_rewrites": [
              "path": "change-password/",
              "method": "PATCH",
              "match_pattern": "change-password/",
              "rewrite_to": "users/"
  "proxy": {
    "preserve_host_header": false,
    "listen_path": "/change-password/",
    "target_url": "http://service-user-dev:3030/",
    "strip_listen_path": false

And the users/ endpoint actually needs an ID, like: users/123, but when I request the gateway endpoint change-password/123, it redirects to users/ without the ID. How can I make it pass along the ID as well?

P.S. I was digging in here but could not find some easy “how-to” explanation of writing rewrites. Any guidance?

Hi Galioy,

in this case you should use a RegEx.
users\/(\w+) should work.

Let me know if this helps.

Kos @ Tyk Support Team

Hi Kos,

I changed it to users\/(\\w+) - just an additional backslash before w+, because it was an invalid string otherwise.

So, it doesn’t work. It redirects to /users/%28%5Cw+%29 :smiley:

Hi Gailoy,

one of our engineers was able to reproduce this, you may try the following:

"match_pattern" : "/change-password/(\d+)", "rewrite_to": "/users/$1"

Let me know if this helps.

Kos @ Tyk Support Team


Hi Kos,

It worked! Thanks. (I only had to add an escaping backslash before \d+, because otherwise it was rendered as an invalid string). :slight_smile:

Now, where could I read about this pattern, using $1, in the docs? I went through them but couldn’t find something related. Maybe I missed it… It would be useful, if there’s a concise list of patterns to use when writing up gateway configs (or smth like that).

Hi Galloy,

im glad to hear that it worked !

There is no such a section in our Documentation.

Kos @ Tyk Support Team

1 Like