Why does the wildcard or regular expression for crawling exclusion files not work according to path prefix matching?
The reason why wildcard or regular expression is not effective when excluding files is that this protocol was never intended to express 'pattern' from the beginning. It does only one thing: it determines whether to exclude based on the prefix of the requested path. The protocol only recognizes two fields, and the matching rule is so simple that it only checks whether 'the path starts with a certain string.' Understanding this point is essential to explaining why many seemingly reasonable formats are treated as a plain prefix by the crawler.
Which two fields does the protocol recognize?
This crawling exclusion standard only uses two commands: User-agent and Disallow. User-agent declares the rules for which crawling party, and Disallow declares the exclusion of which path prefix. It doesn't even have an Allow field - in the early versions, the need to explicitly allow a sub-path could not be expressed, and had to be circumvented by other means.
Because there are only two fields, the expressiveness of the rules is very limited: what follows a Disallow is a string of characters treated as a path prefix, not a pattern string.
Why only match by prefix
The protocol clearly states that globbing (wildcard) and regular expressions are not supported in the User-agent and Disallow lines. That is, the crawler takes the Disallow value you wrote and directly compares it to the path part of the request URL, aligning from the beginning. If it matches, it is excluded; if it does not match, it is not excluded.
| The rule you wrote | How does the crawler actually understand | Result |
|---|---|---|
| Disallow: /admin | Exclude all paths that start with /admin | As expected |
| Disallow: /*.php | Treat as literal, matching paths starting with「*.php」 | Almost no matches |
| Disallow: /tag/[^0-9] | Treat as literal prefix, not a regular expression | Not effective |
What will happen with wildcard and regular expression syntax
Writing wildcard or regular expression not only does not cause an error, but it is also more dangerous—it ‘appears to take effect’ but actually does not. You think/*-page-\d+Blocking all pagination addresses, the crawler is actually looking for a path starting with a slash, a star,-page-, backslash, d, plus sign, this literal character string, almost never matches. The result is: you think the excluded path is usually crawled
Similarly, want to rely on?Wildcard query parameters, want to[]Matching character set, none of these rules are valid in this set. The protocol itself reminds: The crawler can choose to ignore this file, so it is never a security boundary, but just a declaration of intent for compliant crawlers.
What order should the rules be written in the site?
In practice, follow three steps. Step, translate the requirements into 'prefix' instead of 'pattern': to exclude a directory, write the directory path ending with a slash, and to exclude a category of naming conventions, find their common path prefix.Second step, each excluded directory is on a separate line, the rule blocks are separated by blank lines, and different User-agent groups are blocks.The third step, cooperate with the on-site pseudo-static rules to change the controllable dynamic address into a stable, prefix-clear path, and then exclude it will be more accurate - because after pseudo-static, the filtered pages and list pages have become neat directories, and prefix matching can express it clearly.AnQiCMS can be configured directly in the background for Robots.txt, and it also supports custom static rules. When used together, they can clearly express the 'blocked path' with a prefix language.
Common questions
Question: Can I only block pages with a certain parameter?Answer: This file is not enough. It only matches the prefix of the path, and the query parameters cannot be precisely expressed in the prefix rules. You need to use another mechanism or process it on the server.
Question: If there is no error when writing the regular expression, does it take effect?Answer: No. No error does not mean the format is accepted, regular expressions are treated as literal prefixes and cannot match the target path. Check the match results instead of relying on syntax passing.
Question: If the crawling file is blocked, will the content not be crawled?Answer: No. The protocol itself acknowledges that the crawling party can ignore this statement, which is an intention rather than a requirement. The real content to be protected should fall on the server's permissions and frequency limits.