Advanced Configuration: URL Patterns
BFilter allows you to block an arbitrary URL (web address) and to assign hints to URLs in order to influence the heuristic analyzer. In any case you assign some kind of a tag to a URL, so both blocking and hinting (and more) are specified in the same file. Actually there are two files: urls and urls.local, which have only two differences:
1. urls is shipped with BFilter and will be overwritten when you upgrade it.
2. urls.local has a higher priority, so it can override rules specified in urls.
Both files are accessible with the GUI. You are going to make changes to urls.local only. The other one is read-only.
In case you want to know where those files are located:
1. On Windows they are typically located in C:\Program Files\BFilter\conf.
2. On a Mac, they are located in /Library/Application Support/BFilter.
3. On Unix-like systems they can be located in /usr/local/etc/bfilter, /usr/etc/bfilter, or in /etc/bfilter. In case of the GUI version, urls.local is in $HOME/.bfilter, and the one in /usr/local/etc/bfilter is just a template.

The file specifies a number of rules. Each rule has the following syntax:
TAG url_pattern
TAG can be one of the following:
  • HTML: output a blank page.
  • IMAGE: output a transparent image.
  • FLASH: output a blank flash file.
  • JS: output an empty JavaScript file.
  • AD: output an appropriate blank/transparent content.
  • FORBID: output an error page.
  • ALLOW: cancel any of the above tags.
  • NOFILTER: don't filter a page or a script.
  • +++ (any number of plus signs): be more suspicious about the URL.
  • --- (any number of minus signs): be less suspicious about the URL.
  • +N or -N (where N is a number): alternative syntax for the above.

Hints

The last two tags are special. They provide a hint to the heuristic analyzer and are only considered when we already have an ad suspect. For example if we have a clickable image on a page, we are going to consider hints for:
  • The image URL.
  • The link URL.
  • The page URL.
Sometimes an ad can't be blocked with hints. It happens if BFilter doesn't see it (probably because of a problem interpreting a script), or doesn't support that kind of ads (text ads, hover ads). In that case you may still block it using other tags.
Note that hints don't intersect with other tags. When we are looking for a hint, we don't consider other tags, and the other way around.

Patterns

BFilter supports two types of patters:
  • Simple strings with wildcards.
  • Regular expressions.
The wildcards are ? and *, meaning respectively "any character" and "any number of any characters".
Example:
FORBID http://ads.somehost.com/*
This will block any URL starting with http://ads.somehost.com/
Note that for broad ad-blocking patterns like this, I'd recommend using AD rather than FORBID, which would cause error pages in place of IFRAME ads.

Regular expression patterns must be enclosed within two slashes:
JS /http://(www\.)?somehost\.com/ads/.*\.js/
This regex can be interpreted like this: match "http://", optionally match "www.", match "somehost.com/ads/", match any number of any characters, match ".js".
You may find a tutorial and a complete reference on regular expressions here.

Note that both simple and regex patterns are case insensitive.

Compatibility with AdBlock

AdBlock is a popular extension for the Firefox web browser. It's patterns are mostly compatible with BFilter, except they are not anchored, meaning that
http://www.evil.com/*
will also match http://www.good.com/?ref=http://www.evil.com/

In BFilter, patterns must cover the whole URL, not just a part of it. Of course, you are free to write something like this:
+++ *ads*
or
+++ /.*ads.*/
to achieve the same effect.