Skip to main content

URL Rewrite

Overview

The URL Rewrite action allows you to transform the URL path and query parameters of the incoming request.

Example

Use this action config in your Traffic Policy

# snippet
---
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
fromstringA regular expression string to match inside of the URL.
tostringA regular expression string to replace the from match with. Also contains special named variables outside of regular regex.

Named Variables

KeywordDescription
$argsReplaces $args with a list of "&" delimited query parameters: "args1=value1&arg2=value2&...&argn=valuen"
$authorityReplaces $authority with the hostpost of the request url.
$query_stringReplaces $query_string with a list of "&" delimited query parameters: "args1=value1&arg2=value2&...&argn=valuen"
$is_argsReplaces $is_args with "?" if args are present, "" if not.
$uriReplaces $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.
$schemeReplaces $scheme with the scheme of the request, either http or https.
$hostReplaces $host with the host of the request url.
$portReplaces $port with the port of the request url.
$userReplaces $user with the user information of the request.
$is_userReplaces $is_user with an "@" when user is not empty.