Having trouble getting redirect to work

1. Caddy version (caddy version):

2.3.0

2. How I run Caddy:

docker-compose up -d

d. My complete Caddyfile or JSON config:

jump.systems.dance {
redir / /guacamole 308
reverse_proxy http://192.168.1.60:8081 {
flush_interval -1
}
}

3. The problem I’m having:

I want to redirect every single request to towards the /guacamole subdirectory on the server, while hiding it in the address bar.

5. What I already tried:

Tried “/*” instead of just “/”, also tried /guacamole both with the trailing slash and without

6. Links to relevant resources:

Found in Reverse Proxy Guacamole - #4 by francislavoie that this is how you are supposed to do this, but the redirect isn’t working for me.

Also tried this version similar to the one found in the link provided in the OP:

jump.systems.dance {
  @wrongPath {
    not path /guacamole/*
  }
  redir @wrongPath /guacamole/
  reverse_proxy http://192.168.1.60:8081 {
    flush_interval -1
  }
}

Redirect not happening. And:

jump.systems.dance {
  redir / https://jump.systems.dance/guacamole 301
  reverse_proxy http://192.168.1.60:8081 {
    flush_interval -1
  }
}

Doesn’t work either.

You’d want a rewrite then, not a redirect. A redirect is telling the browser to make a new request at a URL, by responding with the Location header in the response.

You probably want this:

jump.systems.dance {
  rewrite * /guacamole{path}
  reverse_proxy http://192.168.1.60:8081 {
    flush_interval -1
  }
}

But be aware that you may run into issues if guacamole is not aware of this:

Wait a moment. Trying out your configuration I’ve discovered a wholly unexpected fail from the undersigned. My docker-compose was pointing to the wrong Caddyfile so the changes I was trying out weren’t actually live in my containers. The redir works now.

:thinking: okay then. But know that redir will not let you achieve what you wrote here:

The redir directive will not hide it from the address bar, because redir literally tells the browser “hey, change the address bar to this!”

The “hiding” is done by doing rewrites, internally at the server.

Yeah, the redir works now but I guess you are right regarding the rewrite and address bar.

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