Redirect remove trailing slash

Hi, I’m trying to create a redirect that redirects the /flower path to /flower/ and this is my current config:

d. My complete Caddy config:

:80 {

  handle /flower {
    redir /flower/ 301

  route /flower/* {
    reverse_proxy localhost:5555 {

  reverse_proxy localhost:8080 {
    header_up Host {host}

This appears to not work, it seems that the /flower path is going to the reverse_proxy rule rather than the handle. However, I thought that the ordering was handle → route → reverse_proxy, so not sure why this is happening.

If I move the redir to top level (redir /flower /flower/ permanent), it starts working, but just curious why this first approach didn’t work.

Thanks for any help!

The reason this doesn’t work is because redir /flower/ 301 has /flower/ as the matcher, not as the redirect target. You’d need to do redir * /flower/ 301 instead. so that * is the matcher (matching all paths, but in reality only /flower because of being inside of handle /flower).

This is useless, Caddy already passes through the Host as-is.

This can be dangerous. Be careful with this. Do you actually have a proxy in front of Caddy? If so you should use its IP or IP ranges.

Also you can move trusted_proxies to global options which has a bunch of additional benefits like having client_ip in access logs. See Global options (Caddyfile) — Caddy Documentation

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