Shadowrocket Custom Rules: Priority, Matching Order, FINAL, PROXY, DIRECT & REJECT

Learn how Shadowrocket rules are evaluated: first match wins, FINAL goes last, and how to order DOMAIN-SUFFIX, GEOIP, PROXY, DIRECT, and REJECT rules.

At a glance

With Config selected under Home → Global Routing, Shadowrocket checks rules in the active configuration from top to bottom. The first match determines the policy. This guide is for users who already have a configuration and want to add exceptions or change the default route. Use the examples to see which rule matches a domain or IP, then test a new connection to distinguish ordering issues from a mode mismatch or an outbound connection failure.

How matching works: the first match decides

Shadowrocket does not collect every matching rule and then choose the most specific one. A domain can match both an exact rule and a suffix rule; the one that appears first takes effect. Once a rule selects a policy, later rules are ignored for that connection. If a connection using PROXY fails, Shadowrocket does not continue down the list and try DIRECT.

New connectionIdentify destinationCheck rules in orderApply policy
1 rule
The first matching rule determines the result
2 fields
A FINAL rule has only a keyword and a policy
3 policies
Policies used here: PROXY / DIRECT / REJECT

Troubleshooting order: find the matching rule, then test the outbound connection

If a domain that should connect directly is routed through PROXY, first check whether a suffix rule above it is matching. Investigate the connection only after the matched rule is the one you expect.

Rule example: domain exceptions first, IP rules next, FINAL last

This is a complete example of a [Rule] section, not a full configuration file. example.com and 198.51.100.0/24 illustrate matching ranges; they are not targets for availability testing. When editing an existing file, adjust the relevant lines in its existing [Rule] section. Do not add a second section with the same name or append rules after FINAL.

[Rule]
DOMAIN,portal.example.com,DIRECT
DOMAIN,ads.example.com,REJECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,198.51.100.0/24,REJECT
GEOIP,CN,DIRECT
FINAL,PROXY

Domain rules

DOMAIN
portal.example.com matches exactly and uses DIRECT
DOMAIN
ads.example.com matches exactly and uses REJECT
DOMAIN-SUFFIX
example.com and its subdomains use PROXY, except for domains matched by the first two rules

Put exact exceptions first, followed by rules covering a wider set of domains.

IP rules and the fallback

IP-CIDR
If the destination IPv4 address is within 198.51.100.0/24, use REJECT
GEOIP
If the geolocation database classifies the destination IP as CN, use DIRECT
FINAL
Use PROXY if none of the preceding rules match

Put explicit network-range exceptions before broad geolocation rules.

Assuming Shadowrocket can identify the destination hostname, portal.example.com matches the first rule and connects directly, even though it also matches the third. cdn.example.com skips the two exact-match rules and is proxied by the third. If you move the third rule to the top, both portal.example.com and ads.example.com match the suffix rule first, and the more specific rules below it will never take effect.

DOMAIN-SUFFIX,example.com,PROXY matches on domain boundaries, so notexample.com is not treated as a subdomain. For the rule's domain field, enter only a hostname or suffix—not https://, a port, or a URL path. For example, the rule value for https://portal.example.com:443/login is portal.example.com. This rule cannot distinguish /login from other paths.

FINAL and GEOIP: default policy vs. address-based matching

GEOIP,CN,DIRECT checks the destination IP, not the device's location or whether the domain ends in .cn. If no domain rule matches and the request still has a domain as its destination, IP-based rules need a resolved address to evaluate. The same domain can resolve to different addresses depending on the network, DNS, or CDN routing, so a GEOIP rule may produce different results on different networks. To keep a known domain on a specific route, add an explicit domain rule before the IP-based rules.

RuleWhen no earlier rule matchesWhen to use it
FINAL,PROXYSend the connection through the current proxy.List specific direct and rejected destinations first; send everything else through the proxy.
FINAL,DIRECTConnect directly to the destination.Use the proxy only for destinations explicitly matched by an earlier PROXY rule.
FINAL,REJECTReject the connection.Only destinations explicitly covered by the rules are allowed; missing dependent domains, such as those for login or images, can break functionality.

Keep one FINAL rule and put it at the end of the rule section. If the current configuration already has FINAL,DIRECT and you want unmatched traffic to use the proxy, replace that line—do not add another FINAL,PROXY after it. Likewise, changing FINAL will not affect a destination already matched by GEOIP,CN,DIRECT. Check the IP's geolocation or add a domain exception before GEOIP.

Rules not taking effect? Test each change with a new connection

  1. Check the mode and configuration file. Under Home → Global Routing, select Config. Then open Config and confirm that the active file is the one you just saved. Global Proxy and Direct modes are separate from the PROXY and DIRECT policies in rule lines. When testing manual rules, do not mistake behavior under Scene for the matching result under Config.
  2. Back up the original configuration and change one thing at a time. For example, move a DOMAIN rule that should connect directly above the DOMAIN-SUFFIX rule that matches it. Leave DNS, proxy outbounds, and FINAL unchanged for now. Save the file and confirm it is active so you can identify what caused any change in the test result.
  3. Start a new connection to a real destination. Replace the example values with a test domain you can access. Fully quit and reopen the test app to reduce the chance of reusing an existing connection; simply refreshing a page may keep the old connection. If a page uses multiple domains, check the main document and any failing resources separately. The address bar alone does not reveal how every request on the page is routed.
  4. Record the matching rule and the connection result separately. Check the available connection logs for the destination hostname or IP, matching rule, and policy. If the expected PROXY rule matched but the connection timed out, first check whether the current proxy outbound is reachable. If the log shows DIRECT when you expected PROXY, go back to [Rule] and find the first matching rule from the top.

Common questions about custom rules

Why does a DOMAIN rule still match the suffix rule?

Move the DOMAIN rule above the DOMAIN-SUFFIX rule that includes it, then verify the hostname used by the actual request. The address bar might show portal.example.com, while a redirect sends the request to another domain. An exact-match rule does not expand to cover redirected domains.

I changed FINAL. Why does this site still connect directly?

Check whether an earlier DOMAIN-SUFFIX, IP-CIDR, or GEOIP rule already matches it. Start a new connection to a real test destination that does not match any earlier conditions, then check whether the fallback changed its route. Do not test FINAL with a destination already matched by an earlier rule.

Will my domain rules still apply if I enter an IP address directly?

If matching has only the destination IP available and no hostname, do not expect DOMAIN or DOMAIN-SUFFIX to match. To make an exception for a specific IPv4 address, use a single-address rule such as IP-CIDR,198.51.100.42/32,DIRECT and place it before any broader network range that includes the address. Replace the example address with the one you want to manage.

Why can't I find my manually added rules after switching configurations?

Open the active file in Config and check whether the rule is still in [Rule]. Switching configurations does not automatically merge rules from the previous file. If you need to keep local changes, back up the old file first, then merge the required exceptions into the configuration you plan to use. Also check for duplicate FINAL rules.

Download Shadowrocket