Uri replace or insert prefix

What would be the syntax to “insert” a prefix to a path?

Was wanting to do something like this:

                        uri_substring:
                        - find: *
                          replace: /path/im/inserting/{path}

(yaml config)

However, the * does not work.

Basically, for all requests to the proxy I want to hit the upstream with the same path but with /path/im/inserting inserted in the front of the path.

Don’t use uri_substring, use uri instead.

The value would be /prefix{uri}.

Using {uri} makes sure the query part is also preserved, otherwise only rewriting with {path} would drop the query.

1 Like

Thank you! Heh - we thought we had it working and did not see your answer right away. You can guess why we came back to look? Yep - weirdness with the query string. :slight_smile:

1 Like

@Ray_Johnson I realized reading this again that you’re using YAML, so I don’t think {uri} is correct, because that’s a Caddyfile placeholder shortcut:

So you likely instead want {http.request.uri}

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.