# Path Rewriting Settings

This reference covers all of Pomerium's **Path Rewriting Settings**:

- [Prefix Rewrite](#prefix-rewrite)
- [Regex Rewrite Pattern](#regex-rewrite)
- [Regex Rewrite Substitution](#regex-rewrite)

These settings affect only the *requests* sent to an upstream service. Pomerium will not rewrite responses from an upstream service based on these settings. This includes any link URLs or paths to JavaScript or CSS assets.

In general, if you want to expose an upstream service under some URL path prefix, you will *also* need to configure the service so it is aware of this path prefix. Otherwise, absolute URLs in the response may be incorrect and the service may not function correctly.

## Prefix Rewrite

If set, **Prefix Rewrite** indicates that during forwarding, the matched prefix (or path) should be swapped with this value.

### How to configure

**Core:**

| **YAML**/**JSON** setting | **Type** | **Usage**    |
| :------------------------ | :------- | :----------- |
| `prefix_rewrite`          | `string` | **optional** |

### Examples

```yaml
from: https://from.example.com
to: https://to.example.com
prefix: /admin
prefix_rewrite: /
```

**Enterprise:**

**Kubernetes:**

| **[Annotation name](https://www.pomerium.com/docs/deploy/k8s/ingress.md#set-ingress-annotations)** | **Type** | **Usage** |
| :-- | :-- | :-- |
| `prefix_rewrite` | `string` | **optional** |

A request to `https://from.example.com/admin` would be forwarded to `https://to.example.com/`.

## Regex Rewrite

If **Regex Rewrite** or **Regex Rewrite Substitution** are set, the URL path will be rewritten according to the pattern and substitution, similar to [`prefix_rewrite`](https://www.pomerium.com/docs/reference/routes/path-rewriting.md#prefix-rewrite).

### How to configure

**Core:**

| **YAML**/**JSON** setting    | **Type** | **Usage**    |
| :--------------------------- | :------- | :----------- |
| `regex_rewrite_pattern`      | `string` | **optional** |
| `regex_rewrite_substitution` | `string` | **optional** |

### Examples

```yaml
regex_rewrite_pattern: '^/service/([^/]+)(/.*)$'
regex_rewrite_substitution: "\\2/instance/\\1"
```

**Enterprise:**

**Kubernetes:**

Kubernetes does not support **Regex Rewrite**
