Skip to content

url

url modifies URL components by ordered rules. It can change scheme, host, path, query, fragment, and port.

yaml
server:
  http:
    middlewares:
      rewrite_url:
        url:
          rules:
            - path_match:
                - /api/**
              modify:
                strip_prefix: /api
                path_prefix: /v1
                add_query:
                  source: turna
            - always_match: true
              modify:
                scheme: http

Match Fields

FieldDescription
always_matchRule always matches.
host_matchHost doublestar patterns.
path_matchPath doublestar patterns.

Avoid mixing host_match and path_match in the same rule; use separate ordered rules when both dimensions matter.

Modify Fields

FieldDescription
schemeReplace URL scheme.
hostReplace URL host and also update r.Host.
portReplace the port when a host is set.
pathReplace the path completely and skip other path modifications.
path_prefixAdd a path prefix.
path_suffixAdd a path suffix.
strip_prefixRemove a path prefix.
path_replaceRegex used for path replacement.
path_replace_withReplacement for path_replace.
add_queryQuery parameters to add.
set_queryQuery parameters to set.
remove_queryQuery parameter keys to remove.
fragmentReplace URL fragment.

The first matching rule is applied, then the request continues to the next middleware.