Shadowrocket Rules: Route Specific Websites Through a Proxy with DOMAIN-SUFFIX and FINAL

Learn to route selected websites through a proxy using DOMAIN-SUFFIX or DOMAIN-KEYWORD, set FINAL to DIRECT for all other traffic, and understand rule matching order.

At a glance

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.

2 rules
Rule lines in the minimal example, excluding the section name
3 fields
Sample domain rule: type, domain, policy
2 fields
Sample fallback rule: FINAL, DIRECT

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.

  1. Open a copy of the configuration

    Go to Config and 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.

  2. Save and enable

    After saving your changes, return to the Config list, 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.

  3. Set the routing mode

    Go to Home → Global Routing → Config and select Config. Keep Config selected during testing; do not use Proxy or Direct instead, or substitute Scene for this fixed test condition.

  4. 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
App requestIdentify destinationMatch rules in orderRoute by policy
Target hostFirst matching ruleExpected route
static.example.comDOMAINDIRECT
example.com or docs.example.comDOMAIN-SUFFIXPROXY
project-only-demo.example.netDOMAIN-KEYWORDPROXY
notexample.com or example.netFINALDIRECT

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.

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.

Download Shadowrocket