In Shadowrocket, put specific exceptions first, broader matches after them, and FINAL last. This guide is for users with a working configuration who want to adjust traffic routing. First check Global Routing and the active Config, then review the syntax examples and use a new connection to verify which rule matches. Any instructions involving PROXY assume you already have your own service and subscription.
1. Confirm Config Is Active Before Checking Rule Order
Saving rule text does not mean the current connection is using it. On Home, check Global Routing; to route traffic using the rules described here, select Config. Then open Config and confirm which configuration file is active. Editing a file that is not selected will not change the matching results for the active configuration.
Proxy, Direct, Config, and Scene in Global Routing are routing modes, not four rule keywords. Proxy and Direct route all traffic through a proxy or connect directly, respectively. Config applies the routing rules in the active configuration. Scene organizes routing behavior by context, so check the active scene when troubleshooting. Do not confuse routing modes with the policies at the end of rule lines.
- In Config, keep a copy of the current file and note the name of the configuration in use.
- Go to Home → Global Routing, select Config, and make sure you are not checking rules under a different routing mode.
- Return to Config, edit the selected configuration, save it, and start a new test request.
- Check the destination and policy in the in-app connection log. If an existing connection is still using the old route, end it and test again.
2. Rules Match Top to Bottom: No Search for a “More Specific” Match
Most rules are checked in list order. The first matching rule determines the policy, and later rules are not reordered for the same request. Shadowrocket will not automatically move a later rule to the top just because it contains a longer domain. The configuration author must place exceptions before broader rules.
For example, if DOMAIN-SUFFIX,example.com,PROXY comes before DOMAIN,api.example.com,DIRECT, the first rule matches api.example.com. To connect directly to this subdomain, move the DOMAIN rule above it. These domains are examples for explaining syntax only; they do not represent available services.
[Rule]
DOMAIN,api.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT
Takeaway: Move Exceptions Up Before Adding Duplicate Rules
If a domain is not routed as expected, first check whether an earlier rule already covers it. Adding the same destination again at the end of the list usually will not change which rule matched first.
3. Rule Syntax: Separate Match Conditions from Policies
Most common rules use a comma-separated format: type, match value, policy. FINAL is a special fallback rule and does not need a match value. Use English commas, put one rule on each line, and do not paste an entire configuration into a single match-value field.
| Rule example | What it matches | What to check |
|---|---|---|
DOMAIN,api.example.com,DIRECT | Exact domain | Matches only this domain, not all of its subdomains. |
DOMAIN-SUFFIX,example.com,PROXY | Domain suffix | Matches example.com and its subdomains; it is not a match for arbitrary text containing the string. |
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve | IPv4 network | Matches addresses in the specified range. no-resolve does not actively trigger a DNS lookup to match this IP rule. |
GEOIP,CN,DIRECT | IP geolocation | Uses the configured geolocation database; a domain suffix does not determine an IP address's location. |
FINAL,PROXY | No preceding rule matched | Use as the final fallback. PROXY requires a working proxy outbound. |
Do not include a protocol prefix, webpage path, or port in a domain rule. For example, if a destination URL includes HTTPS, a path, and port 443, the DOMAIN match value should still contain only the hostname. To route traffic by port, use the appropriate port rule instead of appending :443 to the domain.
4. Ordering DOMAIN-SUFFIX, IP-CIDR, and GEOIP Rules
There is no fixed rule-type order that works for every configuration. What matters is putting exceptions before rules that would cover them. A typical order starts with exact-domain exceptions, followed by domain suffixes, specific IP ranges, broader GEOIP rules, and finally FINAL. If a particular IP range needs priority, you can move it higher, but be aware of which requests it may cover.
[Rule]
DOMAIN,api.example.com,DIRECT
DOMAIN,metrics.example.com,REJECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
This snippet illustrates rule order only; do not use it as a replacement for a complete configuration. api.example.com is a DIRECT exception placed before the suffix rule, and metrics.example.com is a REJECT exception placed first as well. Other example.com subdomains use PROXY. The 192.168.0.0/16 rule covers only the specified private range, not every local network address.
- Domain conditions: Use these to express clear intent for a website or subdomain. Do not change the policy for an entire suffix just to handle an exception for one subdomain.
- IP-CIDR conditions: Use these for known address ranges. Whether a domain request has an IP available at this step depends on the resolution flow and options such as no-resolve.
- GEOIP conditions: These usually cover a broad range, and the result depends on the destination IP and the database. If the same domain resolves to different addresses, the match may change.
- FINAL condition: Put this after all specific conditions. Only requests that have not matched a preceding rule use this policy.
no-resolve does not disable DNS resolution for the entire app, nor does it guarantee that this rule can never match a domain request. It limits actively triggering resolution for the IP rule. If the destination is already an IP, or an address is available from an earlier step, check the actual connection log to determine what happened.
5. Choose PROXY, DIRECT, or REJECT for FINAL
FINAL determines what happens to requests that have not been explicitly classified; it is not a retry switch for failed connections. If a preceding rule matches PROXY and the proxy connection fails, the request does not then fall through to FINAL. To use a backup outbound, check the behavior of the relevant policy group instead of relying on the final fallback to handle failed requests.
| Fallback rule | How unmatched requests are handled | Check before using |
|---|---|---|
FINAL,PROXY | Send traffic through the proxy outbound. | Your existing proxy is available, and destinations that should connect directly are listed explicitly above. |
FINAL,DIRECT | Connect directly to the destination. | Destinations that need a proxy are covered by earlier rules, and you are comfortable connecting directly to other destinations. |
FINAL,REJECT | Reject all other requests. | You have established a sufficiently complete set of allow rules and can troubleshoot missing login, image, or API requests. |
DIRECT may still be handled by a system-created VPN tunnel, but its outbound policy does not use a proxy server; it does not mean Shadowrocket is turned off. REJECT blocks requests at the rule level and does not automatically determine whether a request is “useful.” If a domain serves multiple functions, rejecting the entire domain may also disrupt normal features.
Takeaway: Choose a Fallback for Unclassified Traffic
First identify the destinations that need exceptions, then decide how to handle the remaining requests. Do not cycle FINAL among the three policies just to clear a single error.
6. Verify Changes and Roll Back
Check the destination, matching rule, and outbound policy together; a page loading successfully does not by itself prove the configuration is correct. Browser cache, existing long-lived connections, and requests to multiple domains on the same page can all make the apparent result differ from the scope of the new rule.
- Keep a baseline: Save the original configuration before editing, and note a destination that works along with the current routing mode.
- Make small changes: Change one rule or its order at a time, save, and confirm that the file is still selected in Config.
- Start a new connection: Close and reopen the test page. If needed, end the app’s existing connection before making another request.
- Check the log: Find the actual hostname or IP in the in-app connection log and check the matching rule and final policy, not just the website’s main domain.
- Restore the baseline: If something goes wrong, undo the last rule change or reselect the saved configuration, then test the same destination again.
If your configuration comes from a remote source, also check whether an update overwrote your local changes. Updating a server list and updating a Config rule file are separate operations; verify each update target. Keep custom rules you want to retain in a configuration you can manage and roll back.
7. Common Questions About Custom Rules
Why does traffic still use PROXY when I added DIRECT?
Go to Home → Global Routing and confirm Config is selected, then open Config and make sure you edited the active file. Next, check for a DOMAIN-SUFFIX or other rule above DIRECT that covers the same destination. Move the specific exception up and test it with a new connection.
What happens if FINAL is at the top?
FINAL acts as a fallback for requests that reach it, so specific rules below it will not work as intended. Move it to the end of the rule list, keep one clear final fallback, and check that the conditions above it cover any destinations that need special handling.
Why did login and images break after I added REJECT?
Check whether the rejected domain also serves login, image, or API requests. First remove the REJECT rule to restore the baseline, then use the connection log to narrow the match. DOMAIN-SUFFIX rejects the entire domain group, not a specific webpage path.
GEOIP did not match the region associated with the website. Is the rule broken?
Not necessarily. GEOIP checks the location assigned to the destination IP in the database, not where the site operator is based. Check the actual resolved address and matching log entry. To handle a specific domain consistently, add an explicit domain rule before GEOIP.