URL Rewriting
The URL rewriting feature allows users to redirect matching requests to other URLs by returning HTTP 3xx redirect responses. Rewriting the URL of HTTPS requests requires configuring MITM and installing a CA certificate. Below is a detailed explanation of each field:
-
match (string), required
A regular expression for URL matching, which matches the full request URL (including protocol, hostname, path, and query parameters). Capture groups are supported.
-
location (string), required
The redirect target URL. Supports referencing capture groups with
$1,$2, etc. -
status_code (integer), required
The HTTP redirect status code (
301permanent redirect,302temporary redirect,307temporary redirect preserving method,308permanent redirect preserving method). -
disabled (bool), optional
Whether to disable this rule.
Configuration Example
url_rewrites:
- match: "(.*google)\\.cn"
location: $1.com
status_code: 307
- match: "^https://old\\.example\\.com/(.*)$"
location: "https://new.example.com/$1"
status_code: 301
In the first example, the system will find all requests whose URL matches (.*google)\.cn and rewrite the URL to the corresponding .com domain, while setting the returned HTTP status code to 307.