caddyserver / replace-response

Caddy module that performs replacements in response bodies
Apache License 2.0
98 stars 27 forks source link

How append prefix /aaa on all url? #18

Closed PHCSJC closed 5 months ago

PHCSJC commented 1 year ago

I want to append prefix /aaa on all url of respond, how write? thanks!

francislavoie commented 1 year ago

That's non-trivial. There's no bullet-proof regular expression that could accurately replace all URLs. It entirely depends on the context of the strings (the text surrounding the URLs).

You should configure or change your upstream app to add the prefix.

mholt commented 5 months ago

If we make some assumptions, for example, static HTML documents:

replace stream {
    ` src="/` ` src="/aaa/`
    ` href="/` ` href="/aaa/`
}

Closing, but feel free to continue discussion if needed