Shadowrocket Custom Rules: Rule Order and the FINAL Fallback

Learn how Shadowrocket checks rules from top to bottom and stops at the first match, how PROXY, DIRECT, and REJECT differ, and why FINAL belongs at the end.

At a glance

This guide is for users who have already added their own service details and want to adjust traffic routing in Shadowrocket. First, check that Home → Global Routing is set to Config. Then review rule order, domain and IP conditions, and the placement of FINAL. Finally, inspect a single request to confirm which rule matched. The example domains and addresses illustrate syntax only; they are not usable service details.

First, confirm that Config routing is active

Adding a rule to a file does not mean it is being used for the current connection. Home manages connections and service selection, Config manages configuration files, and Settings manages app preferences. Before troubleshooting, confirm both which configuration is active and which Global Routing mode is selected. Don’t just check whether the new line appears in the file.

Proxy, Direct, Config, and Scene under Global Routing are connection modes. Uppercase PROXY, DIRECT, and REJECT in a rule are the actions applied after a match. These terms belong to different levels. This guide covers rule order in the Rule list of the active configuration when Global Routing is set to Config.

Global RoutingWhat to checkHow it relates to these rules
ConfigConfirm which file is active in ConfigThis is the mode used to test routing based on the rules in the configuration.
ProxyConfirm the selected proxy service is availableThis mode routes connections through a proxy; it cannot verify the full order of Config rules.
DirectCheck whether the device’s current network can reach the destination directlyThis mode connects directly and cannot verify whether a rule’s PROXY action matches.
SceneCheck the active Scene and its settingsConfirm what the Scene actually does before analyzing configuration rules; don’t infer the result from the Scene name alone.

Settings → On Demand controls conditions for connecting on demand. It does not move one domain rule ahead of another. Keep the connection state stable during testing to avoid mistaking a connection change triggered by a network switch for a rule that isn’t taking effect.

Rule priority: the first match wins

The Rule list is not sorted by “domains always take priority over IPs” or “longer rules automatically take priority.” For requests whose match conditions can be evaluated, Shadowrocket checks rules from top to bottom and applies the action on the first match. Later regular rules cannot override it. Put specific exceptions before broader conditions.

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

For a request to api.example.com, the first domain rule matches, so the result is DIRECT. For www.example.com, the first rule does not match, but the suffix rule on the second line does, so the result is PROXY. A request to example.net reaches FINAL only if none of the earlier rules match.

3 actions
This guide covers PROXY, DIRECT, and REJECT
4 key rule types
Focus on DOMAIN-SUFFIX, GEOIP, IP-CIDR, and FINAL
1 rule at the end
Keep one FINAL as the fallback in a simplified configuration

If you move the second line in the example above to the top, api.example.com will match the suffix rule first, so the later exact-domain rule will have no effect. This is a common reason a rule appears not to work: the syntax is fine, but an earlier, broader condition has already matched the request.

Rule syntax: domains, IP ranges, and geographic conditions

Regular rules typically use the format “type, match value, action,” with fields separated by English commas and one rule per line. Don’t use non-English commas or put multiple domains in one match field separated by spaces. FINAL is an exception: it has no domain or address condition and is followed directly by an action.

Domains and fallback

DOMAIN
api.example.com,DIRECT
DOMAIN-SUFFIX
example.com,PROXY
FINAL
PROXY

The table above shows how rule types map to the following fields. Separate the fields with English commas in the file.

IP conditions and DNS resolution

IP-CIDR
192.0.2.0/24,DIRECT,no-resolve
GEOIP
CN,DIRECT
no-resolve
Don’t actively trigger DNS resolution for this IP rule

192.0.2.0/24 is a documentation example range, not a service network that should actually be accessed directly.

Domain rules need access to the relevant domain information when matching; IP rules need a destination address they can evaluate. For domain requests, whether DNS resolution occurs also depends on rule options and DNS settings. Adding no-resolve prevents this IP rule from actively requesting resolution, but it does not mean every domain request can match that address range. If results vary between access methods, first check whether the actual destination in the connection record is a domain or an IP address.

Combining PROXY, DIRECT, REJECT, and FINAL

PROXY hands the request to the proxy policy; the specific outbound route depends on the currently selected service or policy settings referenced by the configuration. DIRECT connects to the destination directly. REJECT blocks the request. None of these actions automatically fixes a connection: PROXY cannot correct invalid service settings, and DIRECT cannot guarantee that the current network can reach every destination.

[Rule]
DOMAIN,api.example.com,DIRECT
DOMAIN-SUFFIX,blocked.example.net,REJECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,192.0.2.0/24,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY

This snippet shows only the Rule section, not a complete configuration. If your file already contains [Rule], add the needed rules to that section rather than pasting in another section with the same name. The example puts an exact domain before a broader suffix condition, followed by address and geographic conditions, with FINAL at the end. Set the actual order according to your own access requirements; don’t treat the example as a universal policy.

Two ways to use FINAL as a fallback

FINAL,PROXY
  • List destinations that need DIRECT or REJECT explicitly above.
  • Send all other unmatched requests to the proxy policy.
  • Confirm that the selected proxy service and protocol settings work.
FINAL,DIRECT
  • List destinations that need PROXY or REJECT explicitly above.
  • Connect all other unmatched requests directly over the device’s current network.
  • New destinations won’t use the proxy policy unless you add them to the rules.

These two approaches change where unmatched traffic goes. Choose one and place FINAL after all regular matching rules.

FINAL has no conditions. If it appears in the middle of the list, requests that reach it already have an action, so later regular rules cannot process them. If the file contains multiple FINAL rules, first reduce them to one clear fallback at the end, then continue troubleshooting the other rules.

Edit and test: change one condition at a time

The steps below refer to the Home, Config, and Settings screens. Editing controls may appear in different places on different platforms, so use the file operations available on your current screen. Keep a copy of the original file before testing, and record the test destination, expected action, and actual result. This makes it easier to find the cause if something goes wrong.

  1. Keep a backup

    Open Config, find the file currently in use, and save a copy or export a backup using the available file operations. For a remote configuration, keep a separate local test copy so a later update doesn’t overwrite your test changes.

  2. Edit the rules

    In Config, open the target file’s editing controls and find [Rule]. Move a specific domain rule above any broad suffix rule. Check the English commas, action spelling, and the final FINAL rule, then save.

  3. Confirm the file is active

    In Config, make sure the file you just saved is active, then go to Home → Global Routing and select Config. Editing a copy without activating it does not change the configuration currently in use.

  4. Start a new connection

    Close the test app’s existing connection to the destination. If needed, turn Shadowrocket’s connection switch off and back on, then make a new request. Existing connections may continue using the action selected when they were established, so refreshing a page that reuses a connection isn’t enough to confirm the result.

  5. Check the connection record

    Check the connection records or logs available in the app. Find the destination domain or IP by test time, then verify the action and any visible match details. If the request redirects, check both the original domain and the redirected domain.

The test is whether a new connection to the specified destination uses the expected action, not whether a webpage happens to load. For example, if the new connection shows PROXY but the handshake fails, check the connection settings for your existing service. If it shows DIRECT and matched a broader rule above, adjust the rule order first. These cases require different troubleshooting steps.

What to check when a rule doesn’t take effect

Why does traffic still use PROXY after I added DIRECT?

First, confirm that Home → Global Routing is set to Config, then check in Config which file is active. Search for the destination domain and see whether a broader DOMAIN-SUFFIX rule or an earlier FINAL appears above your rule. Move the specific exception above the broader rule, save, and test again with a new connection.

Why do requests to the same website use different actions?

Check the full domain in the connection record. The main page, images, and login API may use different domains; a rule matching example.com does not automatically cover a separate example.net. Add conditions for the domains actually requested, rather than assuming the browser’s address bar shows all traffic.

Why doesn’t IP-CIDR catch a domain request?

Check whether the destination address in the connection record belongs to the range, whether the connection uses IPv6, and whether the rule includes no-resolve. DNS may return multiple addresses; don’t assume the address from a separate lookup is the one used by this connection. If the destination consistently appears as a domain, try verifying with an exact DOMAIN rule first.

Why did my custom rules disappear after an update?

First, determine whether the update was for an existing service subscription in Home or a remote configuration in Config. The former is separate from the Rule file; the latter may download the file contents again. Check the file’s source and active status. Restore your local backup, then decide whether to maintain a separate configuration or use the update method provided by the remote configuration.

Download Shadowrocket