7 Syntax
Christopher Meng edited this page 2016-06-21 23:49:56 -05:00

GFWList syntax originated from ABP filters.

  • |: Stands for matching from beginning (In URI, it's scheme): e.g.|http://example.com will match:

http://example.com
http://example.com/page
http://example.com.co

It will NOT match (replace www with any subdomain):

http://www.example.com
https://example.com/page
https://example.com
https://www.example.com
https://example.com.co

Same applied to |https://example.com.

  • ||: Stands for matching specific URI, in such a case, no need to write down scheme, e.g. ||example.com will match (replace www with any subdomain):

http://example.com
http://www.example.com
https://example.com
https://www.example.com

It will NOT match:

http://anotherexample.com
https://anotherexample.com
http://example.com.co
https://example.com.co

Note that ABP supports ||example.com/sample to block ADs in both HTTP and HTTPS, but GFWList doesn't absorb this.

  • !: Stands for comments. Line started with ! means NOTHING. This is often useful for rules which need to be kept for future use, or statements for some purposes, examples:

! Checksum: ...
!---------
!---
!###
!!

Note: Any characters after ! are treated as NOTHING irrespective of how tricky, convoluted and far extended, they will NOT be parsed if in one line, but in order to keep the list sorted and regular, GFWList uses a variety of different comment styles.

  • @@: Stands for whitelist rules. Although GFWList was designed to conform to the GFW mechanisms, it still has consideration of whitelist since sometimes there are some exceptions under special circumstances. Thus take a look at this example:

.example.com
@@|http://sub.example.com

It means example.com is suffering a block while http://sub.example.com is not brought in.

Imagine there is a domain example.org, it has 8 subdomains albeit 7 of them are blocked due to whatever reason, only sub.example.org is available. In such a case, rules can be written as:

|http://1.example.org
|http://2.example.org
|http://3.example.org
|http://4.example.org
|http://5.example.org
|http://6.example.org
|http://7.example.org

Granting that these above is correct, they are still not space saving. A better solution is:

.example.org
@@|http://8.example.org

In stark contrast, the latter one is always better.

Note that usually | and || come after @@.