URL Match Pattern
Brief Overview
Match patterns are a way to specify groups of URLs: a match pattern matches a specific set of URLs.
Match pattern structure
All match patterns are specified as strings. Match patterns consist of three parts: scheme, host, and path. The scheme and host are separated by ://.
<scheme>://<host><path>
scheme
The scheme component can be one of the following: http or https.
host
The host component may take one of three forms:
Form | Matches |
* | Any host. |
*. Followed by part of hostname | The given host and any of its subdomains. |
A complete hostname without wildcards | Only the given host. |
Host must not include a port number.
* Note that the wildcard may only appear at the start.
path
The path component must begin with a /.
After that, it may subsequently contain any combination of the * wildcard and any of the characters that are allowed in URL paths or query strings. Unlike host, the path component may contain the * wildcard in the middle or at the end, and the * wildcards may appear more than once.
The value for the path matches against the string which is the URL path plus the URL query string. This includes the ? between the two, if the query string is present in the URL.
For example, if you want to match URLs on any domain where the URL path ends with foo.bar, then you need to use an array of Match Patterns like ['*://*/*foo.bar', '*://*/*foo.bar?*']. The ?* is needed, rather than just bar*, in order to anchor the ending * as applying to the URL query string and not some portion of the URL path.
Neither the URL fragment identifier, nor the # which precedes it, are considered as part of the path.
Examples
Pattern | Example matches | Example non-matches |
https://*/path Match HTTPS URLs on any host, whose path is "path". |
https://mozilla.org/path https://a.mozilla.org/path https://something.com/path |
http://mozilla.org/path (unmatched scheme) https://mozilla.org/path/ https://mozilla.org/a https://mozilla.org/ https://mozilla.org/path?foo=1 |
https://*/path/ Match HTTPS URLs on any host, whose path is "path/" and which has no URL query string. |
https://mozilla.org/path/ https://a.mozilla.org/path/ https://something.com/path/ |
http://mozilla.org/path/ (unmatched scheme) https://mozilla.org/path https://mozilla.org/a https://mozilla.org/ https://mozilla.org/path/?foo=1 |
https://mozilla.org/* Match HTTPS URLs only at "mozilla.org", with any URL path and URL query string. |
https://mozilla.org/ https://mozilla.org/path https://mozilla.org/another https://mozilla.org/path/to/doc https://mozilla.org/path/to/doc?foo=1 |
http://mozilla.org/path (unmatched scheme) https://mozilla.com/path |
https://mozilla.org/a/b/c/ Match only this URL, or this URL with any URL fragment. |
https://mozilla.org/a/b/c/ https://mozilla.org/a/b/c/#section1 |
Anything else. |
https://mozilla.org/*/b/*/ Match HTTPS URLs hosted on "mozilla.org", whose path contains a component "b" somewhere in the middle. Will match URLs with query strings, if the string ends in a /. |
https://mozilla.org/a/b/c/ https://mozilla.org/d/b/f/ https://mozilla.org/a/b/c/d/ https://mozilla.org/a/b/c/d/#section1 https://mozilla.org/a/b/c/d/?foo=/ https://mozilla.org/a?foo=21314&bar=/b/&extra=c/ |
https://mozilla.org/b/*/ (unmatched path) https://mozilla.org/a/b/ https://mozilla.org/a/b/c/d/?foo=bar |
Invalid match patterns
Invalid pattern | Reason |
resource://path/ | Unsupported scheme. |
https://mozilla.org | No path. |
https://mozilla.*.org/ | "*" in host must be at the start. |
https://*zilla.org/ | "*" in host must be the only character or be followed by ".". |
http*://mozilla.org/ | "*" in scheme must be the only character. |
https://mozilla.org:80/ | Host must not include a port number. |
https://* | Empty path: this should be "https://*/*". |