HTTP Engine
HTTP Rewrite

HTTP Rewrite

HTTP rewrite allows users to match URLs with regular expressions, reject or redirect HTTP(S) requests, commonly used for ad blocking, avoiding privacy tracking, and other purposes.

Configuration format:

http:
  # HTTP(S) rewrite, supports multiple strategies such as header, 302, 307, reject
  url-rewrite:
    - ^http://g\.cn https://www.google.com transparent
    - ^https?://www\.google\.cn https://www.google.com 302 # directly return a 302 redirect response
    - ^https?://ad\.example - reject # reject request
  header-rewrite:
    - ^http://g\.cn request-add DNT 1
    - ^http://g\.cn request-del DNT
    - ^http://g\.cn request-replace DNT 1
    - ^http://g\.cn request-replace-regex User-Agent Go-http-client curl
 
    - ^http://g\.cn response-add DNT 1
    - ^http://g\.cn response-del DNT
    - ^http://g\.cn response-replace DNT 1
    - ^http://g\.cn response-replace-regex User-Agent Go-http-client curl

URL Rewrite

transparent

Intercept and modify the request URL, similar to a transparent proxy, and the application is unaware of this, supporting redirecting HTTP/HTTPS.

302 / 307

The HTTP engine returns a 3xx status code and automatically sets the Location field to achieve the purpose of redirection.

reject

Returns a 404 response and an empty response body.

reject-200

Returns a 200 response and an empty response body.

reject-img

Returns a 200 response and a response body of 1px gif.

reject-dict

Returns a 200 response and a response body of {}.

reject-array

Returns a 200 response and a response body of [].

HTTP Header Rewrite

Header rewrite allows users to add, delete, or replace any header of HTTP requests/responses.

request-add / response-add

Add headers to HTTP requests/responses.

request-del / response-del

Delete headers from HTTP requests/responses.

request-replace / response-replace

Replace the value of headers in HTTP requests/responses.

request-replace-regex / response-replace-regex

Replace the value of headers in HTTP requests/responses with regular expressions.

Using JavaScript Engine Rewrite

If the above functions cannot meet the requirements, please refer to Using JavaScript Engine Rewrite HTTP.