Adblock Plus and (a little) more

Rewriting URL instead of blocking · 2018-05-18 18:17 by Hubert Figuière

Starting with Adblock Plus 3.2 for Chrome, Firefox and Opera (and development builds as of, there is a new $rewrite filter option to rewrite the URL of a resource instead of blocking it.

When Adblock Plus matches a request URL with a filter that has the $rewrite option, it will transform the URL following the provided rule, and tell the browser to load the resource using this new URL instead.

The syntax of the rewrite rule is as follow: you specify a string that serves as a template for the new URL. $n gets substituted with the regular expression n-th submatch of the filter. This is the exact same syntax as JavaScript’s String.prototype.replace() function. If the resulting URL is relative (i.e. it doesn’t have a host), the origin of the original query will be used as the base. In any case, if the new URL doesn’t share the origin, the rewrite will be considered as being failed and initial query will be let through.

Furthermore, $rewrite filters are ignored for requests of the type SCRIPT, SUBDOCUMENT, OBJECT and OBJECT_SUBREQUEST, for security reasons.

This option is convenient to modify or strip query parameters.


This will simply rewrite the requests for “” to be a request for “”

This will rewrite the request to stripping the query string: $1 matches “”.

The will remove the “tracker” query parameter from the request URL.

Update (2019-04-19):
Starting with Adblock Plus 3.5, the $rewrite filter option can also redirect the request to a set of internal resources. Starting with Adblock Plus 3.5.2, the $rewrite filter option can only be used with internal resources. For more information, read the updated documentation.

To the install page


Comment [7]

  1. Arnoh · 2018-05-25 11:37 · #

    How to rewrite “” to “” ?

    Reply from Hubert Figuière:

    You can’t do that. The $rewrite option ensure the origin is kept and will simply ignore the rewrite if the new URL isn’t of the same origin.

  2. cjxlist · 2018-05-27 04:02 · #

    $rewrite is very useful to skip video ads or to avoid warning messages on some websites in China,for now.See EasyList China ​ Already have $rewrite filters to skip video ads on ​ to avoid warning messages on ​ ​ ​
    These websites are very popular in china,could you releasing an ABP officials version ASAP?
    As an maintainer of EasyList China,I had received tons of issue reports about these websites.

  3. Arnoh · 2018-05-29 01:31 · #

    @Hubert Figuière It will be useful if improved this filter to rewrite the URL to a null file (image, script, iframe, xmlhttprequest, stylesheet ….).




    Reply from Hubert Figuière:

    What you want is the redirect option that uBlock has.

    The rewrite option isn’t it.

  4. Arnoh · 2018-05-29 23:19 · #

    or for all types of requests ||$rewerite=abp-null

  5. James Edward Lewis II · 2018-06-10 02:42 · #

    The first example of the rewrite syntax would be ignored because the request would be of type SCRIPT.

    Reply from Hubert Figuière:

    Good call. We added the restrictions on content, but forgot to update the examples in the article. They new are updated.

    Thank you so much for pointing it out.

  6. Fanboy · 2018-06-15 10:54 · #

    Should this work? (changing the token from true to false on twitch)


  7. med · 2018-06-15 13:52 · #

    Your filter is correct but unfortunately request types SCRIPT, SUBDOCUMENT^, OBJECT
    and OBJECT_SUBREQUEST are not rewrited and will be ignored :-/


    Reply from Sebastian Noack:

    This is true, but is that actually the case here? When I go to Twitch, the requests Fanboy appears trying to target seem to be of the type XMLHTTPREQUEST which should be possible to rewrite.

Commenting is closed for this article.