Shadowrocket Custom Rules: Matching Order, FINAL Fallback, and PROXY/DIRECT/REJECT Policies

Shadowrocket evaluates rules from top to bottom and stops at the first match. Learn how to order keywords such as DOMAIN-SUFFIX and IP-CIDR, use FINAL as a fallback, and choose between the three policies.

At a glance

This guide is for users who have already added their own connection details to Shadowrocket and want to edit routing rules. First, set Home → Global Routing to Config, then arrange specific exceptions, broader rules, and FINAL in the active configuration’s [Rule] section. By the end, you’ll be able to use match logs to distinguish rule-order issues from policy choices or connection problems—without repeatedly swapping configurations to troubleshoot.

1. Check Global Routing: When Rules Are Applied

Adding rules does not mean they are being used to process connections. In Shadowrocket, Home manages connections and global routing, Config manages configuration files, and Settings controls app preferences. To test the custom rules in this guide, first select Config under Home → Global Routing, then confirm that Config has the file you just edited selected.

Config

Recommended

Use the policies defined in the current configuration. A request may use PROXY, DIRECT, or REJECT; Config does not mean “DIRECT for everything else.”

Best for: everyday routing and testing custom rules

Proxy

Route traffic through the proxy as the global routing mode, without using the individual rules in this guide to decide how traffic is routed. This can be useful for a brief comparison, but it cannot verify whether a DOMAIN-SUFFIX rule matches.

Best for: checking whether the proxy connection works

Direct

Route traffic directly as the global routing mode. Even if the configuration contains PROXY rules, do not expect them to route traffic in this mode.

Best for: checking the result of a direct connection

Scene in Global Routing selects a routing mode for a particular scenario; it is not the same as the policy field on an individual rule. For troubleshooting, keep the mode set to Config to reduce variables caused by switching scenes. Settings → On Demand controls when connections are initiated based on conditions; it does not decide whether a domain uses PROXY or DIRECT. Starting a connection automatically and routing traffic after it connects are separate functions.

2. Match from Top to Bottom: Put Specific Exceptions Before Broad Rules

A rule list is not a collection where the most specific match automatically takes priority; it is an ordered sequence of checks. Shadowrocket scans from the top, and the first matching rule determines the policy. Later rules do not add to or override the result for that request. Adding a more specific rule farther down cannot undo a match that has already occurred above it.

[Rule]
DOMAIN,account.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

In this example, account.example.com matches DOMAIN first and uses DIRECT. media.example.com does not match the first line, so it reaches DOMAIN-SUFFIX and uses PROXY. If you swap the first two rules, the broader suffix rule will match account before its exception can. Here, example.com is used only to illustrate the syntax; it does not represent an available proxy service.

1 rule
The first matching rule determines the policy for that request
3 policies
Policies used in this guide: PROXY / DIRECT / REJECT
Last
Put FINAL after specific matching rules

When organizing rules, you can check them in this order: specific targets to block, specific exceptions to preserve, broader domain ranges, address ranges, and a fallback. This is a useful checklist, not a fixed template. If a domain must use a direct connection, put that exception before any rule that would otherwise match it. What matters is how rules overlap—not simply the order of their keyword names.

3. Writing DOMAIN-SUFFIX, IP-CIDR, and GEOIP Rules

Domain rules match the request’s hostname; address rules match the destination IP. Both can describe the same service, but they use different matching criteria. Don’t put a domain in an IP-CIDR rule, or include a full URL—with its scheme, path, and query parameters—in a DOMAIN-SUFFIX rule.

KeywordSyntax exampleWhat it matches and what to note
DOMAINDOMAIN,account.example.com,DIRECTMatches the exact domain; does not automatically include other subdomains.
DOMAIN-SUFFIXDOMAIN-SUFFIX,example.com,PROXYMatches example.com and its subdomains; do not add a wildcard asterisk.
IP-CIDRIP-CIDR,192.168.0.0/16,DIRECT,no-resolveMatches an IPv4 range; the prefix length is part of the address range.
GEOIPGEOIP,CN,DIRECTClassifies by the destination IP’s geographic database entry, not by webpage language or domain suffix.
FINALFINAL,PROXYNo match target is specified; matches requests not caught by earlier rules.

192.168.0.0/16 covers addresses from 192.168.0.0 through 192.168.255.255; it does not refer to a single device. To match one IPv4 device, use a /32 rule for its address. A DIRECT rule for a local network can keep matching local destinations from being sent through a proxy, but reachability still depends on the current network, system permissions, and the destination service.

GEOIP results depend on the actual destination address and the contents of the database. A domain ending in .com can resolve to addresses in different regions, and the same domain may use different content delivery addresses on different networks. If you need a fixed policy for a particular domain, use an explicit domain rule rather than guessing how GEOIP will classify it.

4. How PROXY, DIRECT, REJECT, and FINAL Work Together

The keyword defines what to match; the policy field defines what to do after a match. For example, in DOMAIN-SUFFIX,example.com,PROXY, the first two fields specify the match, while the last field specifies how to handle it. FINAL is a special fallback matching rule, not a fourth connection policy.

Put FINAL at the end of the rule list. Since it has no domain or address condition, it catches the remaining requests that reach it. Putting it at the top leaves later specific rules with no chance to match. A standard rule list needs one clearly defined FINAL; stacking multiple FINAL rules does not provide failover.

[Rule]
DOMAIN,blocked.example.com,REJECT
DOMAIN,account.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY

The example above illustrates a set of routing decisions: reject a specified host, preserve a login exception, send other example.com requests through a proxy, then handle local-network and GEOIP conditions, and finally send remaining requests through PROXY. It is not a one-size-fits-all configuration. To connect directly to targets that aren’t listed, change the last line to FINAL,DIRECT and note that unlisted targets will then connect directly.

5. Edit the Active Config: Back Up, Save, and Retest

Before you start, you should already have your own service provider and connection details, and have confirmed that the selected connection works. A one-time client purchase is not a service plan; this site does not provide, sell, or recommend nodes or subscriptions. Editing rules changes how existing connections are selected; it does not fix expired credentials or an unreachable server.

  1. Back up the current configuration

    Go to Config, confirm which configuration file is selected, and save a copy or export a backup first. Note the existing [Rule] contents and FINAL policy so you don’t have to reconstruct the rules if an edit goes wrong.

  2. Keep the routing mode fixed

    Go to Home → Global Routing → Config. Note the current proxy selection. During testing, avoid changing Settings → On Demand or switching networks at the same time.

  3. Edit the rules

    Return to Config, open the editor for the active configuration, and locate [Rule]. Place specific exceptions before any broader rules that would match them. Edit the existing section rather than adding a second [Rule] section.

  4. Save and select the file

    Save your changes and confirm that this file is still selected in Config. If you edited a copy, switch to that copy before returning to Home to check the connection status. This helps avoid testing a file that isn’t active.

  5. Start a new request

    Reconnect and test a specific exception, a broader rule, and a fallback target separately. If needed, save your work, then disconnect and reconnect to reduce the chance that a reused connection affects the result.

Importing a subscription and managing Config are different actions. Updating an existing server subscription mainly affects connection entries; updating a remote configuration may replace rule contents. If local changes disappear afterward, check which type of item was updated. For custom rules you need to maintain, keep them in a local configuration copy you control, and check for changes after each remote configuration update.

6. Verify Matches: Check the Rules Before the Webpage

Whether a webpage opens tells you the outcome of one visit, but it doesn’t prove that a rule is correct. A page usually connects to multiple domains: the main page might use DIRECT while images, verification endpoints, or media use other policies. When troubleshooting, look in the connection log for the specific destination host, matched rule, and final policy—not just the page title or loading speed.

What to checkExpected result in the example aboveCheck this first if the result differs
account.example.comMatches DOMAIN and uses DIRECTIs the specific rule above DOMAIN-SUFFIX?
media.example.comMatches DOMAIN-SUFFIX and uses PROXYIs the edited Config selected? Is there an earlier rule that takes precedence?
192.168.1.20Matches the local-network IP-CIDR rule and uses DIRECTThe subnet mask, rule order, and actual destination IP
A target not matched by any earlier ruleMatches FINAL and uses PROXYThe FINAL policy, and whether an earlier rule already matched

The domains in the table are for illustrating rule evaluation, not real test services. For actual testing, replace the examples with targets you’re authorized to access and use the same matching logic to set expectations. Change one variable at a time: adjust the order, then test. Don’t change DNS, proxy protocols, FINAL, and the network environment all at once, or it will be hard to tell what caused the result.

7. Common Issues: Rules That Don’t Work as Expected

Why does traffic still use PROXY after I added DIRECT?

First, check that Home → Global Routing is set to Config, then confirm that Config has the file you just edited selected. Next, scan down from the top of [Rule] to find the first matching rule. If DOMAIN-SUFFIX appears before the specific DOMAIN rule, move the exception up, save, and start a new connection to test it.

Will FINAL,PROXY switch to DIRECT automatically if the proxy fails?

No. FINAL matches requests not caught by earlier rules, and PROXY specifies how to handle them. A failed proxy connection does not make the rule engine go back and switch to DIRECT. Check whether the selected connection is available, or change the policy to suit your needs.

Why does the page still show old content after I added REJECT?

Content already on the page may be cached; that doesn’t mean a new request was made. First, confirm that the destination host exactly matches the rule, then reload and check the new connection log. The page may also use another domain. Don’t assume REJECT failed just because old content is still visible.

Why doesn’t a domain request match my IP-CIDR rule?

First, check whether the actual destination IP is in the specified range. With no-resolve, Shadowrocket won’t resolve the domain just for this rule. If you need a fixed policy for a domain, add a DOMAIN or DOMAIN-SUFFIX rule and place it before any rules that might otherwise match.

Why did the same rule work yesterday but behave differently after an update?

Check which file is selected in Config, the [Rule] contents after the remote configuration update, and whether Home → Global Routing has changed. If the rules are unchanged, check the destination domain, resolved address, and connection log. With GEOIP or IP-CIDR, a change in the destination address can itself change the match result.

Keep a rule list that’s easy to understand: every specific exception should have a clear purpose, every broad rule should have clear boundaries, and FINAL should state where remaining traffic goes. More rules don’t necessarily mean more accurate routing. Being able to trace a request line by line to its matching rule makes future maintenance and troubleshooting easier. For details on protocol settings, see the technical reference. For connection and settings issues, see troubleshooting.

Official App Store listingVerify the developer and app ID