Skip to main content

Host Rewrite

Summary

The Host Rewrite setting preserves the Host header with the preserve_host_header setting. You can customize the Host Rewrite setting with the following options:

How to configure

YAML/JSON settingsTypeUsage
host_rewritestringoptional
host_rewrite_headerstringoptional
host_path_regex_rewrite_patternstringoptional
host_path_regex_rewrite_substitutionstringoptional

Host Rewrite options

1. Preserve Host Header

preserve_host_header passes the Host header from the incoming request to the proxied host, instead of the destination hostname. It's an optional parameter of type boolean that defaults to false.

See ProxyPreserveHost.

2. Host Rewrite

host_rewrite rewrites the Host to a new literal value.

3. Host Rewrite Header

host_rewrite_header rewrites the Host to match an incoming header value.

4. Host Path Regex Rewrite Pattern/Substitution

host_path_regex_rewrite_pattern and host_path_regex_rewrite_substitution rewrite the Host according to a regex matching the path. For example:

host_path_regex_rewrite_pattern: '^/(.+)/.+$'
host_path_regex_rewrite_substitution: \1

This configuration would rewrite the Host header to example.com given the path /example.com/some/path.

The 2nd, 3rd and 4th options correspond to the Envoy route action host related options.

Examples

host_rewrite: 'example.com'