These do not work, it seems that url-rewriter can only edit/substitute the 2nd part of the URL, but not the target-url part. How to make either the target-url or the url-rewriter work?
Yes, this is possible with URL rewrite. From your last response, I assume you have seen this doc.
No, regexes only work for custom domains, listen paths and relative/sub paths.
Yes, you can. A normal URL rewrite can work however, you mention you have 1000+ endpoints so you could have a lot of rewrite rules.
The path_part match-type simply matches the components of the path itself. Each component of the path is split or separated into distinct values based on the / seperator. For example, if a path contains /foo/bar/baz, the string inserted into the value field should be either one of foo, bar or baz
I have shown an example below that triggers the advanced URL for all relative paths
"url_rewrites": [
{
"path": ".*",
"method": "GET",
"match_pattern": "/(.*)",
"rewrite_to": "/anything/fallback_url_if_does_not_match",
"triggers": [
{
"on": "all",
"options": {
"path_part_matches": {
"key_identifier": { // can be any non-spaced value but it must be used in the context trigger
"match_rx": "foo",
"reverse": false
}
},
"query_val_matches": {},
"header_matches": {},
"session_meta_matches": {},
"request_context_matches": {},
"payload_matches": {
"match_rx": ""
}
},
"rewrite_to": "/anything/path_part_matches/$tyk_context.trigger-0-key_identifier-0"
}
]
}
]
Hi Olu, thanks for the reply.
It seems a bit more complicated to use path_part_matches compared to basic match_pattern.
However that might be more sophisticated and more flexible.
Could you please hint where these details are documented?
I found very minimal references to part_path_matches in Tyk docs and I’ve ended up in browsing Tyk source code along with debug logs to compose a working solution, but without this triggers+options tricks. With that regex I can cover all my 1000+ cases with one rule. Of course the actual groups must be improved/limited ( compared to “(.*)”), yet a single well formed regex can match all that I need.