<!-- review: finished -->

<a id="http-sub"></a>

# Sub

The module is a filter that modifies a response by replacing one specified string with another.

When [building from the source code](https://en.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild),
this module isn't built by default;
it should be enabled with the
`‑‑with‑http_sub_module`
[build option](https://en.angie.software//angie/docs/installation/sourcebuild.md#configure).

In packages and images from [our repos](https://en.angie.software//angie/docs/installation/index.md#install-packages),
the module is included in the build.

<a id="configuration-example-44"></a>

## Configuration Example

```nginx
location / {
    sub_filter '<a href="http://127.0.0.1:8080/'  '<a href="https://$host/';
    sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
    sub_filter_once on;
}
```

<a id="directives-47"></a>

## Directives

<a id="index-0"></a>

<a id="sub-filter"></a>

### sub_filter

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter` string replacement;   |
|------------------------------------------------------------------------------------------|------------------------------------|
| Default                                                                                  | —                                  |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

Sets a string to replace and a replacement string. The string to replace is matched ignoring the case. The string to replace and replacement string can contain variables. Several `sub_filter` directives can be specified on the same configuration level. These directives are inherited from the previous configuration level if and only if there are no `sub_filter` directives defined on the current level.

<a id="index-1"></a>

<a id="sub-filter-last-modified"></a>

### sub_filter_last_modified

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_last_modified` `on` | `off`;   |
|------------------------------------------------------------------------------------------|--------------------------------------------|
| Default                                                                                  | `sub_filter_last_modified off;`            |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

Allows preserving the `Last-Modified` header field from the original response during replacement to facilitate response caching.

By default, the header field is removed as contents of the response are modified during processing.

<a id="index-2"></a>

<a id="sub-filter-once"></a>

### sub_filter_once

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_once` `on` | `off`;   |
|------------------------------------------------------------------------------------------|-----------------------------------|
| Default                                                                                  | `sub_filter_once on;`             |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

Indicates whether to look for each string to replace once or repeatedly.

<a id="index-3"></a>

<a id="sub-filter-types"></a>

### sub_filter_types

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_types` mime-type ...;   |
|------------------------------------------------------------------------------------------|-------------------------------------|
| Default                                                                                  | `sub_filter_types text/html;`       |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

Enables string replacement in responses with the specified MIME types in addition to `text/html`. The special value "\*" matches any MIME type.
