I have the following url_rewrite rule to catch optional query parameters:
{
“path”: “v1/flightplan?{param}”,
“method”: “GET”,
“match_pattern”: “(.)\?(.)”,
“rewrite_to”: “Give yourself a better website » MY DOMAIN”
}
with listen path:
…“listen_path”: “/avio/”,
“target_url”: “Give yourself a better website » MY DOMAIN”,
“disable_strip_slash”: false,
“strip_listen_path”: true,…
The problem is, that the query params must be in the request, otherwise this rewrite rule is not getting considered at all.
How can I construct match_pattern universally for all my endpoints (w/o query params)?
I have now like this:
{
“path”: “v1/flightplan”,
“method”: “GET”,
“match_pattern”: “(.)\?(.)|(.*)”,
“rewrite_to”: “http://tyk-cp-test/vagend/DownloadServlet?$2”,
“triggers”: null
},
If I want to get query params, I have to put ?$2 at the end, but then if therare any, I get the rewrote URL like this: /vagend/DownloadServlet? ← with “?” at the end. Not wrong, but not pretty.
huh, there can be x query params. Imagine service with sorting, pagination, filtering, … with query params.
I’m searching for a universal regex solution for all GET endpoints, otherwise it will strip query params off by default.
I think this should do the trick: (\??.)
{
“path”: “v1/flightplan”,
“method”: “GET”,
“match_pattern”: "v1/flightplan(\??.)",
“rewrite_to”: “http://tyk-cp-test/vagend/DownloadServlet$1”
}