Skip to content

Commit 58a91a4

Browse files
authored
Merge pull request #887 from AdguardTeam/feature/urltransform_clarifications
Fix the description of the $urltransform modifier and update the tracker bypass example
2 parents 6a51063 + 931d321 commit 58a91a4

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

docs/general/ad-filtering/create-own-filters.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ Rules with `$replace` modifier are supported by AdGuard for Windows, AdGuard for
29422942
29432943
#### **`$urltransform`** {#urltransform-modifier}
29442944
2945-
The `$urltransform` rules allow you to modify the request URL by replacing text matched by a regular expression.
2945+
The `$urltransform` rules allow you to modify the request URL by applying a series of transformations.
29462946
29472947
**Features**
29482948
@@ -2954,7 +2954,8 @@ The `$urltransform` value can be empty for exception rules.
29542954
29552955
**Multiple rules matching a single request**
29562956
2957-
If multiple `$urltransform` rules match a single request, we will apply each of them. **The order is defined alphabetically.**
2957+
If multiple `$urltransform` rules match a single request, they are applied one-by-one in lexicographical order, each
2958+
rule being applied to the result of the previous one.
29582959
29592960
**Syntax**
29602961
@@ -2996,7 +2997,7 @@ This section only applies to AdGuard for Windows, AdGuard for Mac, AdGuard for A
29962997
:::
29972998
29982999
As stated above, normally `$urltransform` rules are only allowed to change the path and query parts of the URL.
2999-
However, if the rule's `regexp` begins with the string `^http`, then the full URL is searched and can be modified by the rule.
3000+
However, if the value of the `$urltransform` modifier begins with the string `/^http`, then the full URL becomes the input for, and can be modified by, the rule.
30003001
Such a rule will not be applied if the URL transformation can not be achieved via an HTTP redirect (for example, if the request's method is `POST`).
30013002

30023003
**Examples**
@@ -3046,23 +3047,37 @@ Many websites use tracking URLs to monitor clicks before redirecting to the actu
30463047

30473048
Below is an example of how to obtain the clean destination link to bypass tracking websites and go directly to the destination.
30483049

3049-
In our example:
3050+
In our first example, the destination URL is percent-encoded:
30503051

3051-
1. The initial URL (with click tracking): `https://www.aff.example.com/visit?url=https%3A%2F%2Fwww.somestore.com%2F%26referrer%3Dhttps%3A%2F%2Fwww.aff.example.com%2F%26ref%3Dref-123`
3052-
1. Tracking URL after decoding special characters: `https://www.aff.example.com/visit?url=https://www.somestore.com/`
3053-
1. The website you want to visit: `https://www.somestore.com`
3052+
1. The initial URL (with click tracking): `https://www.aff.example.com/visit?url=https%3A%2F%2Fwww.somestore.com%2F&ref=ref-123`
3053+
1. The website you want to visit: `https://www.somestore.com/`
30543054

3055-
To clean the URL, we first need to decode special characters (like `%3A` → `:`, `%2F` → `/`, etc.) and extract the real URL from the tracking parameters. We will use the `$urltransform` modifier to do this. The following 4 rules replace URL-encoded symbols with their real characters:
3055+
To clean the URL, extract the encoded destination from the `url` parameter and decode it with the `pct` transformation:
30563056

3057-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3A/:/`
3058-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%2F/\//`
3059-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3F/?/`
3060-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3D/=/`
3061-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%26/&/`
3057+
```adblock
3058+
/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=([^&]*).*/\$1/|pct
3059+
```
3060+
3061+
The first transformation extracts `https%3A%2F%2Fwww.somestore.com%2F`, and `pct` decodes it to `https://www.somestore.com/`.
30623062

3063-
After that, we need to write the rule that will block the tracking website and redirect you directly to the target address (somestore.com):
3063+
If the full target URL with a tracking parameter is Base64-encoded, the same approach can be used with the `b64` transformation,
3064+
followed by another substitution that removes the tracking parameter:
30643065

3065-
`/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com.*url=([^&]*).*/\$1/`
3066+
1. The initial URL (with click tracking): `https://www.aff.example.com/visit?url=aHR0cHM6Ly93d3cuc29tZXN0b3JlLmNvbS8/cmVmPXJlZi0xMjM=`
3067+
1. The website you want to visit: `https://www.somestore.com/`
3068+
3069+
```adblock
3070+
/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=([^&]*).*/\$1/|b64|/[?&]ref=[^&]*//
3071+
```
3072+
3073+
The first transformation extracts `aHR0cHM6Ly93d3cuc29tZXN0b3JlLmNvbS8/cmVmPXJlZi0xMjM=`, and `b64` decodes it to
3074+
`https://www.somestore.com/?ref=ref-123`. The final substitution removes the `ref` tracking parameter.
3075+
3076+
:::caution Changing the origin
3077+
3078+
Note that in both rules, the `$urltransform` value starts with `/^http`, so the full request URL is transformed. Without this prefix, only the path and query parts of the URL can be transformed.
3079+
3080+
:::
30663081

30673082
Tracking links will now be automatically cleaned up, allowing direct navigation to the destination website without tracking.
30683083

0 commit comments

Comments
 (0)