文件 設定 Rematch

Rematch

嚴格來說它不是一個真正的代理協議,而是一種特殊出站:命中它之後不會真正發出連線,而是給流量打個標籤,重新跑一遍規則匹配(或跳轉到某個子規則)。

設定範例

config.yaml YAML
proxies:
  - name: "rematch"
    type: rematch
    target-rematch-name: "rematch1"
    target-sub-rule: "sub-rule1"

欄位說明

target-rematch-name可選

覆蓋流量 metadata 中的 rematch-name 標籤,之後可以用 REMATCH-NAME 規則匹配這個標籤。

target-sub-rule可選

填寫後會直接進入指定的子規則繼續匹配;如果名稱不存在或留空,則回退到主 rules

使用範例

標記後繼續匹配主規則
YAML rematch-name
proxies:
  - name: "mark-streaming"
    type: rematch
    target-rematch-name: "streaming"

rules:
  - REMATCH-NAME,streaming,Streaming
  - DOMAIN-SUFFIX,netflix.com,mark-streaming
  - MATCH,DIRECT

請求首次命中 DOMAIN-SUFFIX,netflix.com,mark-streaming 時,會給流量寫入 rematch-name: streaming 並重新進入規則匹配;這次會優先命中前面的 REMATCH-NAME,streaming,Streaming

REMATCH-NAME 規則要寫在觸發 rematch 的規則之前,否則重新匹配時可能再次命中同一個 rematch 出站,形成死循環。

跳轉到子規則
YAML sub-rule
proxies:
  - name: "use-ai-rules"
    type: rematch
    target-sub-rule: "ai-rules"

rules:
  - DOMAIN-SUFFIX,openai.com,use-ai-rules
  - MATCH,DIRECT

sub-rules:
  ai-rules:
    - DOMAIN-SUFFIX,openai.com,AI
    - MATCH,DIRECT

命中 use-ai-rules 後會直接跳到 ai-rules 子規則繼續匹配。子規則裡建議加一條 MATCH 兜底,避免匹配不到任何規則。