When does a rewrite rule take effect?
Save and enable the rule, ensure the global Rewrite gate is on, and send a new request to verify the result.
Manual
A NetPeek rewrite combines match conditions with actions, letting you edit headers, replace bodies, mock a response, block a request, redirect traffic, or return a local file without changing the app under test.
Rewriting changes traffic without changing code: add headers, replace response fields, mock APIs, block ads, redirect. A rule = a condition (when it applies) + an action (what to do). Beginners use Simple mode — a few taps.
| Intent | Use |
|---|---|
| Edit Header | Add / change / delete a request or response header |
| Edit Body | Replace a piece of text in the response/request body |
| Mock response | Skip the real request and return custom content |
| Block request | Return empty response / JSON / image — great for ad & tracker blocking |
| Redirect | Send the request to another URL (e.g. prod → staging) |
| Local file | Serve a file on the device as the response |
Expert mode lets you write the rule statement directly for full power. The first symbol of an action (^ replace, ~ delete, or an @ whole-request verb) decides what; the following @req.*/@rsp.* decides where; quotes hold the value.
"; curly quotes silently break a rule.| Object | Meaning | Example |
|---|---|---|
@req.host | Request host | @req.host CONTAINS "example.com" |
@req.api | Path | @req.api BEGINSWITH "/api/v1" |
@req.url | Full URL | @req.url MATCHES ".*\.jpg(\?.*)?$" |
@req.query | Query string | @req.query CONTAINS "debug=1" |
@req.method | HTTP method | @req.method == "POST" |
@req.port / @req.schema | Port / scheme | @req.schema == "http" |
@req.header["Name"] | Request header | @req.header["Content-Type"] CONTAINS "json" |
@req.bodyText | Request body | @req.bodyText CONTAINS "vip" |
@rsp.header["Name"] | Response header | @rsp.header["Content-Type"] CONTAINS "json" |
@rsp.bodyText | Response body | @rsp.bodyText CONTAINS "false" |
@rsp.status / @rsp.statusLine | Status code / line | @rsp.status == "404" |
Compare: == != > < >= <= CONTAINS BEGINSWITH ENDSWITH LIKE (wildcards */?) MATCHES (regex, whole match) IN ANY/ALL/NONE. Logic: && (AND) || (OR) ! (NOT), group with ().
| Action | Meaning | Example |
|---|---|---|
^ | Replace / insert | ^@req.header["X-Debug"] "1" |
~ | Delete | ~@req.header["Authorization"] |
@mock | Return a custom response | @mock "{\"ok\":true}" |
@reject* | Empty content (empty / image / object / array) | @reject-array |
@redirect | Redirect (or @301…@308) | @redirect 307 "https://test/x" |
@map-local | Serve a local file | @map-local "/shared/mock.json" |
@break | Break the request | @break |
Cond: @req.host CONTAINS "api.example.com" && @req.api BEGINSWITH "/feature" Act 1: ^@req.header["X-Debug"] "1" Act 2: ^@rsp.bodyText "\"enabled\":false" "\"enabled\":true"
Save and enable the rule, ensure the global Rewrite gate is on, and send a new request to verify the result.
Yes. Simple mode builds rules from conditions and intent cards, while expert mode keeps the DSL for advanced cases.
Yes. Mock Response can skip the upstream request and return custom content; Map Local can serve a file stored on the device.