When Global Routing is set to Config, the first matching rule determines the policy for a connection. This guide is for first-time rule editors and anyone troubleshooting a rule that isn’t taking effect. You’ll learn to tell domain, address, and fallback rules apart, identify which line matches a request, and verify the result after making changes.
Rule order: from the first match to FINAL
Check a rule’s position in the file before considering how specific it is. Shadowrocket evaluates rules in the order they appear in the active configuration and applies the policy on the first match. A DOMAIN rule does not automatically move ahead of a DOMAIN-SUFFIX rule. To make an exception for a single host, place it before any broader rule that could match that host.
PROXY: The connection is sent through the proxy. Whether it can connect depends on the availability of the selected proxy server.DIRECT: The connection goes out directly over the device’s current network. MatchingDIRECTdoes not guarantee that the destination is reachable.REJECT: The matching connection is blocked. The app may only show a connection failure without indicating which rule caused it.FINAL: Catches connections that didn’t match any earlier rule. UseFINAL,DIRECTorFINAL,PROXY, with no domain or address value; place it last in[Rule].
Rules select a policy for each connection; they don’t assign a fixed label to an entire app. A single page load may connect to separate hosts for the page, static assets, and sign-in, and each connection can match a different rule. When troubleshooting, identify the host for the failed request—not just the host shown in the address bar.
Domain rules: exact hostnames, domain suffixes, and keywords
Domain rule values contain only a hostname or keyword. For https://www.example.com:443/docs, the hostname is www.example.com; leave out https://, port 443, and path /docs. The results below assume the destination hostname is available for matching.
| Rule and match value | Matches | Does not match |
|---|---|---|
DOMAIN,example.com | example.com | www.example.com |
DOMAIN-SUFFIX,example.com | example.com、www.example.com | notexample.com、example.com.example.net |
DOMAIN-KEYWORD,example | example.net、notexample.com | www.test.invalid |
Use DOMAIN to target one host. Use DOMAIN-SUFFIX to cover the root domain and its subdomains. Suffix matching respects domain-label boundaries; it doesn’t simply check whether a string ends in example.com. DOMAIN-KEYWORD searches for a string anywhere in the hostname without requiring a whole-label match. If you’re targeting one known domain, a keyword may also match unrelated domains.
Address rules: IP-CIDR ranges and GEOIP regions
IP-CIDR checks whether a destination IPv4 address falls within a specified range. GEOIP checks the location associated with the destination IP in the geolocation database. A region code does not indicate a domain suffix, where a website is registered, or where the device is located.
- In
IP-CIDR,192.0.2.0/24,DIRECT,no-resolve,/24means the first 24 bits are fixed.192.0.2.7matches;192.0.3.7does not. To match only the IPv4 address192.0.2.7, use192.0.2.7/32. This example uses a documentation-only address range to demonstrate rule syntax, not to test public internet connectivity. GEOIP,CN,DIRECTsends a connection directly when the destination IP is classified asCNin the geolocation database. A domain ending in.cnis not guaranteed to match, and the visitor’s location does not determine the result. The same domain may resolve to different IPs on different networks, producing different region matches.no-resolvemeans this rule won’t actively resolve a domain to an IP. If a destination IP is already available for matching, the address range can still be checked. It does not disable DNS for the entire configuration or guarantee that later rules won’t use a resolved address.
If a host must always use the same policy, don’t replace its domain rule with an IP address from a one-time lookup. Put the specific domain rule before address rules so the exception can be handled as soon as the hostname is known.
Example: match a single-host exception first
Use the snippet below to follow rule order; it is not a complete configuration. It rejects one specific host, proxies other requests under the same domain, then checks a keyword and an IP condition. When adding rules to an existing configuration, put only the rules you need in its [Rule] section and keep a single FINAL at the end.
[Rule]
DOMAIN,api.example.com,REJECT
DOMAIN-SUFFIX,example.com,PROXY
DOMAIN-KEYWORD,example,DIRECT
IP-CIDR,192.0.2.0/24,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,DIRECT
api.example.commatches the domain conditions on the first three lines, but the first line takes precedence, so the result isREJECT. Move the suffix rule to the top and the result becomesPROXY.www.example.comdoes not match the first line. It matches the suffix on the second line and usesPROXY. Even if its destination IP is classified asCN, the laterGEOIPrule won’t override the policy that already matched.example.netdoes not match the domain conditions on the first two lines. It matches the keyword on the third line and usesDIRECT. If the keyword rule were placed ahead of the suffix rule,www.example.comwould also useDIRECTfirst.- A destination address of
192.0.2.7matches the fourth line. Only connections that match none of the first five lines reachFINAL,DIRECT. Since multiple lines can result inDIRECT, the policy name alone doesn’t tell you which rule matched.
Apply rules and verify the result
Before testing, confirm which configuration and routing mode are active, then start a new connection. The steps below use the iPhone / iPad interface. Saving a rule isn’t enough to complete a test: the selected configuration, reused connections, and proxy server status can all affect what you observe.
Check the configuration
Tap
Configat the bottom and confirm which configuration file is selected. Keep a recoverable copy before editing so a single test doesn’t require changing multiple existing rules.Save your changes
Add the rules you want to test to the
[Rule]section of the same configuration. Check that fields are separated by English commas, exceptions appear before broader rules, and then save.Confirm routing mode
Go back to
Home, openGlobal Routing, and selectConfig. IfProxy,Direct, or aScenewas selected before, switch toConfigbefore testing the rule order in this guide.Test a new connection
On
Home, confirm the connection is on. Close the connection used by the test app, then make a new request to a host you know is reachable. CheckDatafor the connection record at that time and verify the destination host, matched rule, and policy. A page loading successfully does not prove thatPROXYmatched.
Connection fails: check DNS and the server first
A browser error can indicate what kind of connection step failed, but it can’t prove on its own that a particular rule matched. Check the record for that request first. If there’s no matching record, confirm the test app opened a new connection and that Shadowrocket is still connected.
Browser errors and what to check
Error: ERR_NAME_NOT_RESOLVED
Cause: The browser couldn’t get a valid resolution for the destination hostname.
Fix: Check the hostname spelling first, then review the DNS settings in the active Config. Don’t try to fix a resolution issue by changing FINAL.
Error: ERR_CONNECTION_RESET
Cause: The connection was reset. This error alone can’t tell you whether the outbound connection or the destination closed it.
Fix: Check the policy in Data first. If PROXY matched, return to Home, run Connectivity Test for the current server, then test the same host again.
FAQ: Why didn’t changing a rule make a difference?
Troubleshoot by symptom
I added DOMAIN. Why is the connection still using the old policy?
First, check in Home → Global Routing that Config is selected. Then look in the active rule section for an earlier DOMAIN-SUFFIX, DOMAIN-KEYWORD, or other rule that already matches. Move the exact exception above it and start a new connection.
How do I send just one subdomain directly without changing the whole suffix rule?
Keep the existing suffix rule and add DOMAIN,files.example.com,DIRECT above it. This affects only files.example.com. When the page reloads, requests to other hosts are still handled by their respective matching rules.
Why can I connect by IP but not use that to verify my domain rule?
When you enter an IP directly, the test no longer uses the original hostname, so it can’t confirm whether DOMAIN matched. Test with the original hostname and check the connection record. If the browser reports a resolution error, troubleshoot DNS before testing the domain rule again.
How can I tell whether FINAL matched instead of an earlier DIRECT rule?
Check the rule for the connection in Data, not just whether the policy is DIRECT. If the record shows an earlier domain or address rule matched, choose a different test destination. The connection reaches FINAL only when none of the earlier conditions match.