Shadowrocket checks rules in the order they appear in the configuration. The first matching rule determines how a connection is handled, and FINAL catches all remaining connections. This guide is for users who already have a provider and subscription and want to edit Config. Using the iPhone / iPad interface as a reference, it explains rule syntax, ordering, saving, enabling, and testing. Mac, Windows, Android, and Linux users can apply the same rule concepts; editing options vary by platform.
1. Set Global Routing to Config
Custom rules do not necessarily affect connections just because they have been saved. First, check Global Routing on Home: select Config to route traffic according to the rules in your configuration. Proxy applies a global proxy mode, while Direct applies a global direct-connection mode; neither lets you determine whether a particular Config rule matched. Scene switches between scenarios and is not the same as a rule’s policy.
The server selected on Home and the enabled configuration in Config serve different purposes: the former provides connection details for proxy egress, while the latter defines how traffic is routed. Writing PROXY in a rule does not create a working server or fill in its address, port, or password. Get your subscription link from your provider.
2. Understand top-to-bottom matching
The app does not combine all matching results and then choose one, nor does it automatically move “more specific” rules to the top. For connections evaluated against the rules, it checks the list from top to bottom. Once a rule matches, its specified policy applies, and later rules cannot override it. Put exceptions before broader rules, and place FINAL last.
[Rule]
DOMAIN,api.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,PROXY
With this order, api.example.com matches DOMAIN first and uses DIRECT. www.example.com does not match the first rule, but matches the second and uses PROXY. If DOMAIN-SUFFIX were moved to the first line, api.example.com would match the suffix rule first, leaving the exact exception below with no chance to apply.
DOMAIN: Matches an exact domain name; useful for exceptions for a single host.DOMAIN-SUFFIX: Matches the specified domain and its subdomains. Both example.com and static.example.com are included, but notexample.com is not.FINAL: Has no match target; it handles connections not matched by any preceding rule.
3. Rule fields and PROXY / DIRECT / REJECT
In a text configuration, rules go under the [Rule] section. The usual format is “rule type,match target,policy,” separated by English commas. FINAL is an exception: write it as FINAL,PROXY, not as three fields with an empty match target. In the graphical editor, these fields appear separately; do not put the entire rule line in the domain field.
Domain rules and the final rule
- DOMAIN
- api.example.com,DIRECT
- DOMAIN-SUFFIX
- example.com,PROXY
- FINAL
- PROXY
Put exact exceptions first, broader suffix rules after them, and FINAL at the end.
Three routing strategies
- PROXY
- Route through the proxy server
- DIRECT
- Connect directly to the destination without using a proxy server
- REJECT
- Reject matching connections
A policy determines how a connection is handled; it is not a protocol name or a substitute for server settings.
Check the active server and the policy settings in the configuration to confirm where PROXY traffic actually exits. If you use a custom policy group, its name must match the one defined in the configuration. DIRECT does not turn off the system VPN; it means this connection is handled directly. Use REJECT only for targets you explicitly want to block. Avoid applying it to an overly broad domain suffix, or login, image, or verification requests may fail along with it.
[Rule]
DOMAIN,blocked.example.com,REJECT
DOMAIN,api.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,PROXY
In this rule set, blocked.example.com is rejected first. A later rule allowing the same suffix through PROXY will not change that result. The example domain illustrates syntax only; it does not represent a working route or test service.
4. IP-CIDR, GEOIP, and DNS considerations
Domain rules match names, IP-CIDR checks whether a destination address belongs to a specified network range, and GEOIP relies on an IP geolocation database. These are not interchangeable rule types. When accessing a domain, IP-based rules may depend on DNS resolution. If the client does not have domain information available, domain rules cannot reconstruct every original hostname from the destination IP alone.
| Rule example | What it matches | Notes |
|---|---|---|
DOMAIN-SUFFIX,example.com,PROXY | Target domain suffix | Do not include https:// or a URL path. |
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve | IPv4 network range | Covers 192.168.0.0 through 192.168.255.255. |
GEOIP,CN,DIRECT | Database classification of the destination IP | Uses destination IP database records, not domain text or account region. |
FINAL,PROXY | No preceding rule matched | Place it at the end of the rule section. |
no-resolve means the app will not actively trigger domain resolution just to match this IP rule. It does not disable DNS for the entire app or guarantee that the rule will match. The network condition above can match a connection directly targeting 192.168.1.20. For a domain connection without an available IP, do not rely on this rule with no-resolve as if it were a domain rule that must apply.
- For predictable behavior with specific domains, use explicit DOMAIN or DOMAIN-SUFFIX exceptions.
- For LAN access, set IP-CIDR to the actual address range; do not route all addresses through DIRECT.
- GEOIP classification can vary with the database and the resolved destination address. A single match does not establish a website’s permanent geographic classification.
- For IPv6 destinations, use the corresponding IPv6 rule, such as IP-CIDR6. An IPv4 network range does not cover IPv6 addresses.
5. Save, enable, and test rules in Config
Before editing, keep a copy of the current configuration, especially if it comes from a remote URL. Updating a server subscription and updating a remote Config are different operations: the former mainly refreshes server details, while the latter may replace rule content. Do not assume your manual changes remain just because an update succeeded; reopen the active configuration and check.
- Check the configuration. Open Config, find the configuration in use, and keep a copy. Do not clear other sections from the original file.
- Open the editor. Open the configuration’s editing view and add entries to the rule list, or find the
[Rule]section in the text editor. Paste only the rules you need, and avoid inserting duplicate sections with the same name. - Check the order. Place exact domain exceptions and specific LAN rules before broader rules that might match them. Check whether an earlier rule already covers the target.
- Save and enable. Save your changes and confirm in Config that this configuration is selected. Return to Home, set Global Routing to Config, and make sure the connection is on.
- Test a new connection. Close and reopen the target page, and reconnect if needed. Existing long-lived connections do not show how the new rules will handle a fresh connection.
- Review the logs. Check the in-app connection log for the destination domain, IP, matched rule, and policy. If the test fails, restore your copy first, then narrow the changes.
6. Should FINAL use PROXY or DIRECT?
There is no single FINAL policy that works for every configuration. FINAL,PROXY sends otherwise-unclassified connections through the proxy; FINAL,DIRECT connects them directly, while only explicitly matched targets use other policies. Either choice amplifies the impact of omissions in earlier rules, so decide how you want to handle targets that are not listed.
- Use PROXY at the end: Put destinations that should connect directly above it. If proxy egress is unavailable, unclassified connections may also fail; that alone does not mean the FINAL syntax is wrong.
- Use DIRECT at the end: Rules for destinations that need a proxy must appear earlier. If a webpage’s main domain and resource subdomains differ, check the actual requests separately.
- Do not add FINAL too early: It catches every connection not matched earlier, so regular rules written after it cannot be evaluated for those connections.
For initial troubleshooting, avoid using FINAL,REJECT as a general template: it rejects every destination not covered by an earlier rule. A safer approach is to keep a known-working fallback, add REJECT for one clearly identified target, and use the connection log to confirm the scope.
7. Common questions about custom rules
Why does all traffic still go through the proxy after I add rules?
First, check on Home whether Global Routing is set to Proxy. For rule-based routing, switch it to Config. Then confirm that Config has the file you just edited enabled, start a new connection to the target, and check whether an earlier, broader rule matched it.
Should DOMAIN-SUFFIX include a URL prefix or port?
No. Enter example.com as the match target; do not include a URL prefix, path, or :443. DOMAIN-SUFFIX matches domain suffixes, not different ports such as 80 and 443 on the same domain, and it cannot route traffic by webpage path.
If a page opens after I change its policy to DIRECT, does that mean the rule is correct?
It only shows that this visit succeeded. Also check the matched rule and policy in the connection log, then test the page’s resource requests again. Caching, existing connections, and different subdomains can affect what you observe, so a displayed page alone is not enough to confirm the rule.
What should I do if my custom rules disappear after an update?
In Config, check the active file and your saved copy, and confirm whether a remote configuration was updated or a different file was selected. Restore your copy and enable it again, then consider maintaining custom rules in a local copy. Repeatedly refreshing the remote file will not restore manual edits.
PROXY matched, but the connection timed out. Should I change the rules?
Keep the rules you have already verified. On Home, check the selected server and run Connectivity Test, then confirm the address, port, and protocol settings provided by your service provider. Rules determine where traffic goes; they cannot fix an unreachable server, authentication errors, or mismatched transport settings.