Rule order: exceptions first, catch-all rules last

In mode: rule, mihomo checks rules from top to bottom. The first match determines which outbound or proxy group handles the connection. It does not scan the entire list and then choose the most specific match. If a subdomain must use a proxy, put its DOMAIN rule before the parent domain's direct-connection rule; otherwise, the parent suffix rule matches first and the exception never takes effect.

  1. Put essential exceptions first. For example, route api.example.com through a specific proxy group, then decide how to handle other subdomains of example.com.
  2. Next, add known direct-connection domains and rule sets. Check domains first: when a domain is enough to determine where traffic goes, there is no need to wait for a later IP rule to classify it.
  3. Then use GEOIP,CN,DIRECT as a fallback. This rule checks the database classification of the destination IP, not the domain suffix or the service provider's place of registration.
  4. Put MATCH,Proxy Abroad last. It handles connections that did not match any earlier rule. That can include mainland China services you forgot to specify, so treat it as the default route—not as a rule that identifies overseas websites.

Example configuration: direct domains, IP fallback, and proxy group

This example uses fields supported by mihomo v1.19.0. Make a copy of your current configuration for testing, and keep your existing proxies or proxy-providers. Replace Proxy-Node-A with the name of an actual entry in proxies. When adding a proxy group, merge it into the proxy-groups list; do not add a second top-level key with the same name to the YAML file. Arrange rules as a single list in the order shown below.

mode: rule
mixed-port: 7890
allow-lan: false

proxy-groups:
  - name: Proxy Abroad
    type: select
    proxies:
      - Proxy-Node-A

rules:
  - DOMAIN,api.example.com,Proxy Abroad
  - DOMAIN-SUFFIX,example.com,DIRECT
  - DOMAIN-SUFFIX,qq.com,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,Proxy Abroad

DOMAIN matches an exact hostname. DOMAIN-SUFFIX,example.com matches example.com and its subdomains, such as www.example.com, but not notexample.com. Here, example.com illustrates rule priority and does not indicate the domain's geographic location. Enter hostnames in rules without https://, ports, or URL paths.

DIRECT is a built-in outbound. Proxy Abroad is a user-defined select proxy group. When a rule matches this group, traffic uses whichever node is currently selected in it. If nodes come from a proxy provider, reference the relevant proxy-providers key with use in the proxy group instead of adding the provider name to proxies as if it were a node. During testing, do not add DIRECT to this group; doing so can make a group match look like traffic is being forwarded through a node when it is not.

RULE-SET: move direct-connection lists out of the main configuration

As your list of direct-connection domains grows, manage it with rule-providers and keep only the order, individual exceptions, and target policies in the main configuration. Test the file path and format locally before switching data sources. Merge the following definition into the main configuration's rule-providers. If that top-level key already exists, add only the cn-local entry.

rule-providers:
  cn-local:
    type: file
    behavior: classical
    format: yaml
    path: ./ruleset/cn-local.yaml

Create ruleset/cn-local.yaml in the core's working directory. Relative paths use mihomo's working directory as their base, which may differ from the directory containing your subscription file. Desktop clients often set a separate data directory for the core. If the file cannot be found, check the startup log or the client's core-directory option, then verify the path.

payload:
  - DOMAIN-SUFFIX,qq.com
  - DOMAIN-SUFFIX,bilibili.com

Use the classical format for this file. Each entry contains a rule type and a match value; do not append DIRECT at the end of a line. The main configuration's RULE-SET rule specifies the outbound. Replace the previous section with the complete rules list below to have this rule set take over the existing one-line qq.com rule:

rules:
  - DOMAIN,api.example.com,Proxy Abroad
  - DOMAIN-SUFFIX,example.com,DIRECT
  - RULE-SET,cn-local,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,Proxy Abroad

Every entry in a rule set uses the policy specified by its RULE-SET rule. To route a subdomain through a different outbound, add an exact-match exception above RULE-SET. Before using an existing rule set, check its file contents, format, and behavior. For example, a domain-only domain list cannot be read as the classical entries shown above without modification.

GEOIP and DNS: why the same domain can use different outbounds

GEOIP,CN,DIRECT matches the destination IP. If no earlier domain rule matches and the core currently has only a domain, it may resolve that domain when checking the IP rule. A service can return different CDN addresses on different networks, so the same domain may not match the same IP rule on an office network and a mobile network. For a consistent outbound, use a verified domain exception rather than adding an IP from a single DNS lookup.

  • Keep domain-based matching available. If an app sends only a bare IP to the core and the core has no usable domain mapping, DOMAIN-SUFFIX cannot match. Check the connection details first to see whether the core received a hostname or only a destination IP.
  • Use no-resolve with care. With GEOIP,CN,DIRECT,no-resolve, this rule will not actively resolve a domain to check for a match. Connections that already have a destination IP can still be evaluated; connections with only a domain and no available destination IP may fall through to MATCH. If you need GeoIP to help route traffic, do not add this option without considering its effect.
  • Distinguish fake IPs from real destination IPs. With dns.enhanced-mode: fake-ip enabled, the synthetic address seen by an app is used to associate traffic with a domain; it does not indicate the server's geographic location. Do not infer which GEOIP rule matched from a synthetic address. Check the rule and outbound recorded by the client instead.

When some page resources fail to load, check the main document, image CDN, and API requests separately. Use the browser's Network panel to identify the hostname for each failed request, then look up that hostname under Connections in the client. A successful direct connection to the main site does not mean other domains used by the page should also connect directly.

How to test: check the matched rule, not just whether a page loads

For the first round of tests, use an explicit HTTP proxy to ensure requests go through port 7890 in the configuration. After each command, search by domain on the client's Connections or Logs page and check the rule, proxy group, and node actually used. Short-lived connections may disappear quickly, so open the log before sending a request.

curl --noproxy "" -I --max-time 12 --proxy http://127.0.0.1:7890 https://qq.com/
curl --noproxy "" -I --max-time 12 --proxy http://127.0.0.1:7890 https://example.net/
Target What to check If the result differs
qq.com The first version should match DOMAIN-SUFFIX; after adding the list, it should match RULE-SET. Both versions should use DIRECT. Check the active configuration, operating mode, and rule-set loading logs.
example.net If the destination IP does not match GEOIP,CN, it should match MATCH and be handled by the node selected in the Proxy Abroad group. If GeoIP matches, check the resolved IP. If another rule matches, check whether the subscription added more rules.

The 12-second limit applies to a single test request; it is not the node's latency. -I sends a HEAD request, and this example does not follow redirects automatically, so a 301 or 405 response alone does not mean the routing is misconfigured. If the log shows the correct rule but the connection fails, check DNS, connection errors, or node status for the relevant outbound. If there is no log entry, first confirm the listening port and that the request reached the core.

What to recheck after subscription updates, system proxy changes, and TUN setup

  1. Recheck the active configuration after refreshing a subscription. Direct edits to a subscription cache may be lost on refresh. If your client supports overrides or configuration merging, put custom rules in a persistent configuration layer and confirm that exceptions appear before existing rules—not after an existing MATCH. Rerun both test commands after refreshing.
  2. Test the actual app only after the proxy port test succeeds. The system proxy affects only apps that follow that setting. If a browser behaves unexpectedly but an explicit proxy request works, check whether the browser has its own proxy settings and look for the corresponding connection in the client. This helps distinguish traffic that never reached the core from rules that failed to match.
  3. Reconnect after enabling TUN. TUN changes how traffic enters the core; it does not change the matching order of rules. Close existing connections, then test the target app again. Check the connection's network type and destination address, and test TCP and UDP separately. The HTTP proxy commands above test TCP requests only and cannot confirm that UDP is being intercepted.

During maintenance, keep three results that you can reproduce: one exact-match exception, one direct-connection rule-set match, and one default proxy match. When adding an exception, change only the necessary domain or rule order. Avoid changing the DNS mode and traffic interception method at the same time; that way, if something breaks, you can pinpoint the change from the match results.