Rule priority: list order determines the outcome
Start with rules: in the active configuration. In Rule mode, the core checks rules from top to bottom, and the first match determines the policy; later rules cannot override it. DOMAIN doesn't automatically rank ahead of DOMAIN-SUFFIX just because it's more specific, and a single IP won't take priority over a /24 just because it's written as /32. If a custom exception isn't taking effect, first check whether a broader rule appears above it.
rules:
- DOMAIN,api.example.com,REJECT
- DOMAIN-SUFFIX,example.com,DIRECT
- MATCH,DIRECT
If the core has the destination domain, api.example.com matches the first rule and gets the REJECT policy; www.example.com skips the first rule and matches the second. Swap the first two lines, then start a new connection to api.example.com, and the result will be DIRECT. This example uses built-in policies to demonstrate rule order and doesn't depend on subscription nodes.
When rules overlap, put an exception before the broader rule it needs to override. A common order is “specific exceptions → common routing rules → broad rule sets → MATCH,” but the right place for any rule depends on what you want it to override.
DOMAIN-SUFFIX: matches the base domain and its subdomains
Domain rules use three fields: type, match value, and policy. Enter a hostname as the match value—without https://, a port, or a path—and don't write it as *.example.com. For example, when you break down https://api.example.com:443/v1, the value for DOMAIN is just api.example.com. Domain rules can't distinguish between /v1 and /v2 on the same host.
| Rule example | What it matches | Commonly mistaken match |
|---|---|---|
DOMAIN,api.example.com,DIRECT |
Hostname only: api.example.com |
Doesn't match v2.api.example.com |
DOMAIN-SUFFIX,example.com,DIRECT |
example.com and its subdomains |
Doesn't match notexample.com; suffixes are matched at domain-label boundaries |
IP-CIDR,192.0.2.0/24,DIRECT,no-resolve |
A known destination IPv4 address from 192.0.2.0 to 192.0.2.255 |
A connection with only a domain and no destination IP won't trigger a lookup just for this rule |
Use DOMAIN when you only need to route one host. Use DOMAIN-SUFFIX when the site and its subdomains should share a policy. A webpage may also connect to image, login, or API hosts under other domains; each request is matched separately. If the main page loads but login keeps spinning, check the connection log for the hostname used by the login request instead of relying on the browser's address bar.
IP-CIDR and no-resolve: where the destination IP comes from
IP-CIDR checks the destination IPv4 address, not your local address. Use /32 for one IPv4 address, such as 192.0.2.42/32, and 192.0.2.0/24 for the entire example subnet. For IPv6, use IP-CIDR6, for example IP-CIDR6,2001:db8::/32,DIRECT,no-resolve. A domain can return both IPv4 and IPv6 addresses, so an IPv4-only subnet won't cover both types of connection. These addresses illustrate match ranges and aren't targets for reachability tests.
Adding no-resolve determines whether this rule triggers a lookup
- Destination IP already available: For example, an app may connect directly to an IPv4 address. Even with
no-resolve, the core can use the existing address to check whether it falls within the subnet. - Domain only: If there isn't a destination IP to match yet, a rule with
no-resolvewon't resolve the domain just to check the subnet. The core continues to the next rule. - An earlier rule already triggered a lookup: A later
no-resolverule may still use the destination IP that was already obtained. The option prevents this rule from triggering a lookup; it doesn't disable DNS or prevent resolution later in the connection.
To route by domain and add a fallback only for connections made directly to an IP, put the domain rule first and follow it with a subnet rule using no-resolve. To route by the IP returned for a domain, omit no-resolve on the relevant subnet rule and make sure no earlier domain rule matches first. Moving a broad subnet rule without this option higher up may trigger an extra lookup for connections that could have been routed by domain, or match a policy you didn't intend.
RULE-SET and MATCH: put rule sets after exceptions
In Mihomo, rule-providers: defines the source and content type of a rule set, while RULE-SET in rules: determines when it is checked and which policy applies when it matches. The rule set name must match its definition key. With behavior: classical, entries can use rule types such as DOMAIN and DOMAIN-SUFFIX, but don't append DIRECT or a proxy group name to an entry. Set the policy on the RULE-SET line that references it.
rule-providers:
work-domains:
type: file
behavior: classical
format: yaml
path: ./rules/work-domains.yaml
rules:
- DOMAIN,status.example.com,DIRECT
- RULE-SET,work-domains,REJECT
- MATCH,DIRECT
Add the following content to rules/work-domains.yaml in Mihomo's working directory. A GUI client may start the core with a working directory different from the one containing the original subscription file. If the file can't be found, check the core configuration directory shown in the client and the configuration that's actually active.
payload:
- DOMAIN-SUFFIX,example.com
- DOMAIN,api.example.net
With this configuration, status.example.com matches the first rule and goes direct, while other example.com subdomains are matched by the rule set and rejected. Move RULE-SET to the top and it will override the status-page exception. MATCH has only two fields—a rule type and a policy—and needs no match value. It catches every connection that reaches it, so it's usually placed last. If your production config uses a policy such as PROXY, first confirm that the active configuration contains a proxy group with that exact name; names aren't consistent across subscriptions.
Rules not working? Check the active list and test a new connection
- Check the mode and traffic path. Switch the client to Rule mode before testing; Global and Direct modes don't test this rule list. With the system proxy, some apps may bypass it. In TUN mode, first make sure the connection is actually reaching the core. If the destination doesn't appear in the connection list at all, check traffic capture before changing the rule order.
- Inspect the rules actually loaded. Make sure the edited Profile is enabled, then check its merged
rules:list. A custom rule appended afterMATCHwon't run. If a subscription update removes local edits, use the client's supported override mechanism or save the rules in a separate local Profile. In particular, check whether the override is inserted before the original list or replaces the entire list. - Compare expected matches using new connections. Check the destination host, matched rule, and policy in the client's Connections page or the core log; column names vary between clients. Test one connection that should match a specific exception, then another that should match a broader rule. Browsers may reuse existing connections, so close the relevant connection or restart the test app after changing the config, then inspect the new entry.
- Separate a match problem from a forwarding problem. If the rule matches correctly but the request fails, check the selected policy first. A request failing under
REJECTis expected; if a proxy group matches, also check its selected node and connection status. If a connection expected to match a subnet falls through toMATCH, check whether the destination is IPv4 or IPv6, whether the core already has the destination IP, and whether the rule usesno-resolve.
Change only one set of overlapping rules at a time and record the destination, expected match, and actual match. This helps pinpoint whether the order is wrong, the rule wasn't loaded, or the core didn't receive enough destination information to match—without repeatedly switching between the system proxy and TUN modes.