URL Rewrite
Chute can rewrite the request's URL with different methods, or reject certain requests by URL.
Only one rule could be applied for one single request.
Example:
[URL Rewrite]
^http://www\.google\.cn http://www.google.com header
^http://amazon\.cn https://z.cn 302
^http://ad\.com/ad\.png _ reject
^http://tracker\.com/event _ reject-200
^http://ad\.com/pixel _ reject-img
^http://api\.example\.com/block _ reject-dict
The rewrite rule consists 3 parts: regular expression, replacement and type.
For the reject types (
reject,reject-200,reject-img,reject-dict), a two-token shorthand<pattern> rejectwithout the_placeholder is also accepted.
Header Mode
Chute will modify the request header and redirect the request to another host if necessary. The client will not notice this rewrite action. (This mode corresponds to Surge's "Map Remote".)
The "Host" field in request header will be modified to match the new URL.
[URL Rewrite]
^http://www\.google\.cn http://www.google.com header
The replacement may also be a path-only form like /new/path. In that case only the request line is rewritten to the new path, and the request is still sent to the same host.
When the destination cannot be rewritten in place — for example rewriting a plain HTTP request to an
https://URL, or rewriting an HTTPS request (with MitM enabled) to a different origin — Chute automatically falls back to answering the client with a 307 redirect to the new URL instead of a transparent header rewrite.
302 Mode
Chute will simply return a 302 redirect response. HTTPS requests can be redirected if MitM for the hostname is enabled.
[URL Rewrite]
^http://amazon\.cn https://z.cn 302
307 Mode
Chute will simply return a 307 temporary redirect response. HTTPS requests can be redirected if MitM for the hostname is enabled.
[URL Rewrite]
^http://amazon\.cn https://z.cn 307
Reject Mode
Reject the request if the pattern is matched. The replacement parameter will be ignored. Returns an HTTP 503 response. HTTPS requests will be rejected if MitM for the hostname is enabled.
[URL Rewrite]
^http://ad\.com/ad\.png _ reject
Reject-200 Mode
Reject the request with an HTTP 200 OK status and zero-length body. Useful for silently blocking tracking requests without triggering error handling.
[URL Rewrite]
^http://tracker\.com/event _ reject-200
Reject-Img Mode
Reject the request by returning a 1x1 white GIF image (HTTP 200 OK). Useful for blocking ad images without causing broken image placeholders.
[URL Rewrite]
^http://ad\.com/pixel _ reject-img
Reject-Dict Mode
Reject the request by returning an empty JSON object {} (HTTP 200 OK). Useful for blocking API calls that expect a JSON response.
[URL Rewrite]
^http://api\.example\.com/block _ reject-dict