Shadowrocket rules first check whether a request meets a condition, then determine which policy handles it. This guide is for users with their own service details who are ready to edit Config. Learn the six rule types, order them from specific exceptions to broader matches, and put FINAL last. Then verify the result with a new connection. Examples explain syntax and matching scope only; they do not provide service details.
1. Rule format: match type, match value, policy
Rules are commonly added to the [Rule] section of a Config file. Except for special forms such as FINAL, a rule usually has three fields: a keyword, a match value, and a policy, separated by commas. For domain rules, enter the hostname only—not a protocol prefix, URL path, or port.
[Rule]
DOMAIN,account.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT
Here, DIRECT means connect directly, PROXY sends the request through a proxy policy, and REJECT blocks matching requests. Rules determine how requests are handled; they do not create servers or supply authentication details. Before using PROXY, check that your own server is configured and available in Home. If you use a custom policy group, the name at the end of each rule must match its definition in the Config file.
Key takeaway: match the right target
Use DOMAIN when matching one hostname. Use DOMAIN-SUFFIX only when you need to cover an entire domain and its subdomains. Avoid starting with the broader keyword match.
2. DOMAIN, DOMAIN-SUFFIX, and DOMAIN-KEYWORD: what each matches
All three rule types match domains, but their scopes differ. DOMAIN matches an exact hostname; DOMAIN-SUFFIX matches the specified domain and its subdomains; and DOMAIN-KEYWORD checks whether the domain contains a specified string. These are not URL filters: they cannot distinguish pages on the same host by paths such as /video/.
| Rule example | Matches | Does not match / Notes |
|---|---|---|
DOMAIN,example.com,PROXY | example.com | Does not include www.example.com |
DOMAIN-SUFFIX,example.com,PROXY | example.com、www.example.com、a.b.example.com | Does not match notexample.com |
DOMAIN-KEYWORD,example,PROXY | example.com、myexample.net | May match unrelated domains |
For example, to send only the login endpoint directly while proxying other requests on the same domain, put DOMAIN,account.example.com,DIRECT before DOMAIN-SUFFIX,example.com,PROXY. This works because of rule order—not because an exact hostname automatically has higher priority.
- Do not write
DOMAIN,https://example.com,PROXY. The match value should beexample.com. - Do not use
*.example.cominstead of a suffix rule. To match the entire domain, useDOMAIN-SUFFIX,example.com,PROXY. - A webpage may connect to the main site, image hosts, and API hosts. Matching the main site does not mean all its resources will use the same policy.
3. GEOIP and IP-CIDR: match destination IP locations and address ranges
GEOIP matches based on the destination IP's location in a geolocation database. For example, GEOIP,CN,DIRECT sends destination addresses that the database associates with CN to DIRECT. It does not check the webpage language, domain suffix, or server operator's location. Database records also do not necessarily reflect the current physical location.
IP-CIDR matches IPv4 address ranges. 192.168.1.0/24 covers 192.168.1.0 through 192.168.1.255, illustrating the rule's scope; which addresses can be assigned to devices on a local network also depends on its configuration. Use IP-CIDR6 for IPv6 ranges; do not put an IPv6 address in an IPv4 example.
[Rule]
IP-CIDR,192.168.1.0/24,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
/32represents one IPv4 address, while/24represents 256 addresses. The longer the prefix, the smaller the range.no-resolveis an optional parameter. When matching this IP rule, it prevents a domain lookup from being triggered; it does not disable DNS for the entire app.- If a request has a domain but no available destination IP, an IP rule with
no-resolvemay not match. Requests with a destination IP can still be evaluated. - For a local network DIRECT rule, use your actual subnet. Do not assume every home network is the same just because the example uses
192.168.1.0/24.
When combining domain and IP rules, put specific domain exceptions first, followed by broader IP location rules. This helps prevent a destination from matching an earlier policy based on its resolved IP. DNS may return different addresses for the same domain, so the GEOIP result can change with the destination address.
4. Rules run top to bottom and stop at the first match: why FINAL goes last
In a standard linear rule list, requests are checked in order. Once a rule matches, its policy is applied; evaluation does not continue looking for a “more specific” rule. FINAL has no domain or address condition. It catches requests that did not match earlier rules, so it must go at the end of the list.
[Rule]
DOMAIN,account.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,192.168.1.0/24,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,DIRECT
- Request to
account.example.com: the first rule matches and uses DIRECT. The suffix rule below it is not evaluated. - Request to
images.example.com: the first rule does not match, so the second rule matches and uses PROXY. - Request to destination
192.168.1.20: it matches the local network range and uses DIRECT. - Other requests: GEOIP is checked first. If no rule matches, the request uses the DIRECT policy specified by FINAL.
If you put the suffix rule before the exact-host exception, account.example.com will use PROXY first. If you put FINAL,DIRECT at the top, no later rule gets a chance to handle ordinary requests. To proxy only specified sites, list them with domain rules and end with FINAL,DIRECT. To send all other requests through a proxy, use FINAL,PROXY instead; these choices affect different sets of requests.
5. Edit rules in Config and apply them to new connections
Adding rules to a file does not mean that file is active. Check both the selected Config file and Global Routing in Home. To route by Config rules, select Config. Proxy and Direct do not test individual rules in the list described here, while Scene involves scene selection and is not suitable for isolating a basic rule test.
-
Keep a copy of the original Config
Open Config and save a copy of the current file or its original text first. Make sure you are editing the file currently in use, not another Config with the same name.
-
Edit the rule section
In Config, select the target file, open Edit Plain Text, and find
[Rule]. Put specific exceptions first and keep any required FINAL fallback at the end. Leave the file's other required sections intact. -
Save and select the file
Save your changes, return to Config, and confirm that the file you edited is selected. A later remote Config update may overwrite local changes, so keep a copy of the rules you added before testing.
-
Check the routing mode
Return to Home → Global Routing → Config, then check your own proxy server. A subscription update refreshes existing service details; it does not write or enable local rules for you.
-
Test a new connection
After saving, establish a new connection and make the target request again. Check the connection log for the destination hostname, destination IP, and policy used. Do not judge whether a rule matched solely by whether the page opened.
Change one condition at a time when testing. For example, first route one exact hostname through DIRECT; after confirming the result, expand the rule to DOMAIN-SUFFIX. Browser cache, existing long-lived connections, and other domains used by the site can affect what you observe. The new request must actually create a network connection; a cached page does not prove that the new rule was used.
6. Troubleshoot rule behavior separately from network errors
“The webpage won't open” does not necessarily mean the rule syntax is wrong. First check which policy the request actually selected, then investigate DNS and the connection. The messages below are English error descriptions that may come from Apple's networking stack. The app or system may display localized text, so you may not see the exact same wording in Shadowrocket every time.
Error: The request timed out.
Cause and fix: The request did not complete within the allowed time. The destination may be unreachable, or the selected server may have a connectivity issue. Check the connection log to see whether the request used DIRECT or PROXY, then troubleshoot that path. Do not broaden the rule scope as a first step.
Error: A server with the specified hostname could not be found.
Cause and fix: The destination hostname could not be resolved. Check the spelling and the DNS settings in the active Config. Once resolution works, check whether GEOIP or IP-CIDR has the destination address it needs to match.
| What you see | Check first | Next step |
|---|---|---|
| All requests use the same policy | Is Global Routing set to Config? Was FINAL placed at the top by mistake? | Correct the mode or rule order, then establish a new connection |
| The main site behaves as expected, but its images do not | Do the image requests use a different hostname? | Use the connection log to add the actual resource hostname; don't rely on a broad keyword match |
| The exact-host exception did not match | Is there a broader DOMAIN-SUFFIX or DOMAIN-KEYWORD rule above it? | Move the specific exception above the broader rule |
| The IP rule did not match a request to a domain | Is the destination IP available? Is no-resolve enabled? | Distinguish a DNS resolution issue from a rule condition that was not met |
Key takeaway: verify three details with a new request
After each change, note the destination hostname, the policy used, and the matching rule's position. Continue troubleshooting connectivity only after confirming that the request reached the expected policy. Do not confuse a connection failure with a rule that did not match.