Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caddy: Rewrite path to URL parameter

I am currently using Caddy as a reverse proxy.

rewrite / /index.html

https://localhost/ --> https://localhost/index.html

https://localhost/?p1=v1&p2=v2 --> https://localhost/index.html?p1=v1&p2=v2

Now I want to additionally change the path /static to index.html. However, a URL parameter static=true should then be added.

https://localhost/static --> https://localhost/index.html?static=true

This additional URL parameter should not influence the existing parameters.

https://localhost/static?p1=v1&p2=v2 --> https://localhost/index.html?static=true&p1=v1&p2=v2

How do I have to adjust my caddyfile to make this work as desired? I just tried the following, but unfortunately it didn't work.

rewrite /static /index.html?static=true
like image 616
michaelT Avatar asked Feb 06 '26 06:02

michaelT


1 Answers

{query} is the old query params,so can do like this:

rewrite /static index.html?{query}&static=true

the documents: placeholders

like image 190
vishun Avatar answered Feb 09 '26 09:02

vishun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!