For users who have already imported their own server and want most traffic to remain direct. Add a domain rule and a DIRECT fallback in the [Rule] section of your configuration file, then enable the configuration. Test the results against the target domain, a direct-connection exception, and an unrelated domain.
Minimal setup: send the target domain through PROXY and everything else through DIRECT
Add the two rules below to the [Rule] section of a local copy of your configuration. If the section already exists, add or replace rules within it; do not create a second [Rule] section. If a FINAL rule is already present, change it to FINAL,DIRECT and move it to the end. Do not keep a duplicate.
[Rule]
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT
example.com is a sample domain; replace it with the domain you want to route. Enter only the hostname in the domain field—not https://, a port, path, or query parameters. For example, the hostname in https://docs.example.com:443/guide is docs.example.com. If only that host needs routing, use DOMAIN,docs.example.com,PROXY; there is no need to broaden the rule to all of example.com.
Takeaway: define the smallest proxy scope first
If you need to match just one host, start with DOMAIN. Switch to DOMAIN-SUFFIX only if you confirm that other subdomains under the same domain also need the proxy. This makes it easier to identify which rule changed the route when troubleshooting.
Save the rules in Config and enable the configuration
The steps below use the iPhone / iPad interface. Before you begin, make sure Home contains a working server that you imported yourself. To make it easy to roll back, note the configuration file in use and the current Global Routing mode. Do not overwrite the original file you use day to day.
Open a copy of the configuration
Go to
Configand open the local configuration file you want to edit. Find[Rule]and leave the other configuration sections intact. Review the existing rules, then add the minimal example to a test copy.Save and enable
After saving your changes, return to the
Configlist, select the file you just edited, and verify its name. Editing a file does not automatically switch to that configuration. If you have files with identical or similar names, double-check which one is active.Set the routing mode
Go to
Home → Global Routing → Configand selectConfig. KeepConfigselected during testing; do not useProxyorDirectinstead, or substituteScenefor this fixed test condition.Connect and compare results
Return to
Home, make sure the server you want to use is selected, and turn on the connection. Send new requests to the target host and an unrelated host, then check the outbound policy for each. Add an exception or broaden the match only after checking the results.
FINAL,DIRECT only determines where traffic goes when it reaches the fallback rule; it does not change the rules above it to DIRECT. If the existing configuration has GEOIP, IP-CIDR, or rule sets that point to PROXY, unrelated websites may match those rules first. To test the minimal example, remove these conflicts in a test copy rather than appending another FINAL rule to the original file.
Rule order: put specific exceptions before broad matches
Rules in the domain example below are evaluated in order, and the first match determines where traffic goes. To keep static.example.com on a direct connection while routing other hosts under the same domain through the proxy, place the exact-match exception before the suffix rule. If you swap the first two lines, the suffix rule will match static.example.com first, and the later exception will not change the result.
[Rule]
DOMAIN,static.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
DOMAIN-KEYWORD,project-only-demo,PROXY
FINAL,DIRECT
| Target host | First matching rule | Expected route |
|---|---|---|
static.example.com | DOMAIN | DIRECT |
example.com or docs.example.com | DOMAIN-SUFFIX | PROXY |
project-only-demo.example.net | DOMAIN-KEYWORD | PROXY |
notexample.com or example.net | FINAL | DIRECT |
DOMAIN-SUFFIX matches the specified domain and its subdomains. It will not match notexample.com just because the name ends with the same characters. DOMAIN-KEYWORD matches a string anywhere in the domain, so it may match even when the domain suffix differs. It does not search URL paths: for https://example.net/project-only-demo, the domain used for matching is example.net, not the text after the slash. Use a keyword instead of listing hosts individually only when multiple confirmed target hosts share a sufficiently distinctive string.
Test routing: distinguish a rule match from a successful connection
The table above shows the results implied by the rules; it does not test connectivity to the sample domains. To verify the setup, choose three hosts you can test: a target that should use the proxy, an exception that should connect directly, and an unrelated site that should reach FINAL. If connection details show the target host, matched rule, or outbound policy, check those fields first. A page loading successfully by itself does not prove the rules are correct.
- Change one thing at a time. Keep the network and server unchanged, and modify only the rules. Save the file and confirm the active configuration before sending a new request. Your browser may reuse an existing connection or serve a cached page. If needed, quit and reopen the browser, then check for a new connection record.
- Check page resources by host. A page's login, images, and API may use different domains. If the homepage works but one resource fails, first check the host used by the failed request. Add an exact rule only after confirming that host needs the proxy; do not broaden the keyword match indiscriminately.
- Distinguish domain access from IP access. Opening a test target by IP address does not prove that a domain rule matched. If no domain information was available when the request was matched, check the relevant IP rules and fallback result.
- Test server connectivity separately. Use
Connectivity TestonHometo troubleshoot the server connection. Its result does not show that a particular website matchedPROXY, or that all of that website's resources will load successfully.
How to troubleshoot rules that do not work as expected
First determine whether the expected rule failed to match or the correct outbound was selected but the connection failed. The errors below may appear in a browser; they are not Shadowrocket rule errors. They can suggest what to check, but cannot by themselves show which policy handled the traffic.
Error: ERR_NAME_NOT_RESOLVED
Cause: The browser could not resolve the requested hostname. The domain may be misspelled, or name resolution may be unavailable. Fix: Check the hostname from the failed request, then try a known resolvable domain on the same network for comparison. If the issue is name resolution, check your DNS settings.
Error: ERR_CONNECTION_TIMED_OUT
Cause: The connection was not established before the timeout. A timeout alone cannot tell you whether the issue is with the direct route, proxy server, or destination service. Fix: First check the outbound used for this request. If it matched PROXY, run Connectivity Test and compare the result with a known working request that uses the same server.
If the expected rule still does not match, check these items in order: Is the correct configuration file active? Is Global Routing set to Config? Does the host in the actual request match the rule's domain field? Is there an earlier rule that matches first? Once the minimal setup produces the expected result, restore existing rules one group at a time and retest the same hosts. This identifies which change altered the route without repeatedly switching servers.