Skip to main content

Routing Rules

Routing rules (Response Rules, SRR) are an ordered set of rules the panel uses to decide what to return for a subscription request. The decision is made from the HTTP headers of the request: the client can be served a different format, a different template, or different headers, or refused entirely.

note

The rules run on the panel side and never reach the nodes. Xray's own routing (routing.rules) is set in the config profile and applied to nodes — see Config profiles.

Where they are configured​

The rules are stored in the subscription settings as the responseRules object and edited in the rule management section:

{
"version": "1",
"settings": { "disableSubscriptionAccessByPath": false },
"rules": []
}

disableSubscriptionAccessByPath: true closes access to the subscription via additional paths (/json, /mihomo, /stash).

Order of application​

Rules are checked top to bottom. The first matching rule fires, and the check stops there. Rules with enabled: false are skipped. If no rule matches, the request is blocked — that is why the last rule is often one without conditions that serves the regular subscription.

Operators and conditions​

The rule's operator defines how conditions are combined:

OperatorWhen the rule matches
ANDall conditions match
ORat least one condition matches

An empty conditions array always matches — this is the "default rule". Each condition checks a single header:

{
"headerName": "user-agent",
"operator": "CONTAINS",
"value": "happ",
"caseSensitive": false
}
Condition operatorCheck
EQUALS, NOT_EQUALSexact match
CONTAINS, NOT_CONTAINSsubstring occurrence
STARTS_WITH, NOT_STARTS_WITHstart of the string
ENDS_WITH, NOT_ENDS_WITHend of the string
REGEX, NOT_REGEXregular expression

Header names are case-insensitive, several values of the same header are joined with a comma, and a missing header means the condition is not met.

Response types​

responseType determines what the client receives on a match:

TypeResponse
XRAY_JSON, XRAY_BASE64, MIHOMO, CLASH, STASH, SINGBOXthe subscription in the required format
BROWSERan HTML page for the browser
BLOCKrefusal, HTTP 403
STATUS_CODE_404, STATUS_CODE_451refusal with code 404 or 451
SOCKET_DROPconnection drop

Response modifications​

The responseModifications block refines the response:

  • subscriptionTemplate — the template name; it takes priority over external squad settings;
  • headers and applyHeadersToEnd — add headers, at the very end if needed, on top of the others;
  • ignoreHostXrayJsonTemplate — do not use the host's Xray JSON template;
  • ignoreServeJsonAtBaseSubscription — serve base64 even to clients that are normally served JSON;
  • disableHwidCheck — do not check HWID for this rule;
  • additionalExtendedClientsRegex — extend the list of "extended" clients;
  • excludeHostsByTags — remove hosts with the specified tags from the output;
  • respondWithRemarks — replace the response body with text.
tip

A typical scenario: serve Android clients a separate JSON template, and legacy apps — BLOCK. The panel shows an example of such a rule when editing.

danger

A rule without conditions and with responseType: BLOCK will block everyone who reaches it. Order rules from most to least specific and check the subscription after every edit.

What's next​

  • Templates — what is inserted into the response.
  • Squads — the priority of rules over external squads.
  • Hosts — host tags for excludeHostsByTags.
  • Config profiles — Xray routing on nodes.