URL Rewrite
Overview
The URL Rewrite action allows you to transform the URL path and query parameters of the incoming request.
Example
- YAML
- JSON
actions:
- type: url-rewrite
config:
from: v0/user/([0-9]+).*
to: v1/user?id=$1&$args
{
"actions": [
{
"type": "url-rewrite",
"config": {
"from": "v0/user/([0-9]+).*",
"to": "v1/user?id=$1&$args"
}
}
]
}
Behavior
When executed, this action will replace all regex matches with the configured replacement. Before regex replacement, all named variables will be replaced with their corresponding values.
Reference
Supported Directions
- Inbound
Configuration
Type |
---|
url-rewrite |
Parameter | Description | |
---|---|---|
from | string | A regular expression string to match inside of the URL. |
to | string | A regular expression string to replace the from match with. Also contains special named variables outside of regular regex. |
Named Variables
Keyword | Description |
---|---|
$args | Replaces $args with a list of "&" delimited query parameters: "args1=value1&arg2=value2&...&argn=valuen" |
$query_string | Replaces $query_string with a list of "&" delimited query parameters: "args1=value1&arg2=value2&...&argn=valuen" |
$is_args | Replaces $is_args with "?" if args are present, "" if not. |
$uri | Replaces $uri with the request URI: path?query. |
$arg_<name> | Replaces $arg_name with the value of query parameter name if it exists in the request, "" if not. name must only be comprised of digits, letters, and the "_" character. If there is more than one value assigned to name , only the first value will be substituted. |
$scheme | Replaces $scheme with the scheme of the request, either http or https . |
$host | Replaces $host with the hostname of the request. |