# Rewrite Rules

{% hint style="info" %}
**Configures:**

* How to modify parts of a request?
  {% endhint %}

Rewrite rules enable modification of any part of a request. Rules are applied if a request URL matches the provided regex **pattern.** If there are no rewrite rules or a request URL does not match any of the rule patterns, then there will be no modifications to the intercepted request.

## Rule Configuration

<figure><img src="https://3980092275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MLvhXOE-py5MDUOXDKD%2Fuploads%2Fgit-blob-480a9ef791021be7d54d63c1ece60ba34bf717e6%2FScreen%20Shot%202023-04-12%20at%2010.44.04%20AM.png?alt=media" alt=""><figcaption><p>Figure 1. Rewrite rule</p></figcaption></figure>

### Method

HTTP verb(s) the rule applies to such as GET, POST, DELETE, etc.

### Pattern

Pattern to match with the request URL to apply the rule to. This supports regular expressions.

### Parameters

Which components of the request to match on, such as header, body, and query param.

### Name

Name of the component

e.g. for the header `Authorization: Token` , the name is `Authorization`

### Value

Value of the component

e.g. for the header `Authorization: Token` , the value is `Token`

### Modes Applied To

Which agent mode to apply the firewall rule to such as mock, record and/or replay

## Example

For example, say you want to record requests to endpoints that require valid OAuth tokens. Let's say that endpoint is `GET https://internal.company.com/v1/users` . Then you can create a rewrite rule with the following values:

* Method - `GET`
* Pattern - `https://internal.company.com/v1/users`
* Parameter Type - `Header`
* Parameter Name - `Authorization`
* Value - `REDACTED TOKEN`
* Modes Applied To - `Record`

When recording, this will configure the agent to rewrite the `Authorization` header's value with `REDACTED TOKEN`. Similarly, when replaying a request, we can also create a rule set this same header with a valid token. For advance use cases, see:

{% content-ref url="../../../guides/how-to-record-requests/how-to-customize-recordings" %}
[how-to-customize-recordings](https://docs.stoobly.com/guides/how-to-record-requests/how-to-customize-recordings)
{% endcontent-ref %}
