How to redirect www.domain.tld to domain.tld with Caddy on Rocketchat?


(madelung) #1

Hi, on Snap + Caddy install for Rocketchat, how to redirect www.domain.tld to domain.tld?

I can access domain.tld but got an error when i typed www.domain.tld - I got this: “404 Site www.domain.tld is not served on this interface”.

Note: on my domain’s dns, there’s only A and CNAME records.

The Caddyfile looks like this:

domain.tld
proxy / localhost:3000 {
websocket
transparent
}

(Matthew Fay) #2

www.domain.tld doesn’t have a definition in that Caddyfile. You’ll need to add another site definition to tell Caddy how to handle requests for it.

For Caddyfiles with multiple site definitions, you’ll need to put each site’s definition inside a parentheses block; see Caddyfile Structure docs:
https://caddyserver.com/docs/caddyfile#structure

Your second site definition only needs to contain a redirect to the bare domain.
https://caddyserver.com/docs/redir

To avoid double redirects for HTTP requests, define the behaviour for both HTTP and HTTPS like so:

http://www.example.com, https://www.example.com {
  redir / https://example.com
}

(madelung) #3

What should I write in the definition?

Sorry, noob here. Tried many things, nothing’s working.


(Matthew Fay) #4

In the Caddyfile, beneath what you’ve already got. The docs have a visual example:

A code example would look like this:

example.com {
  proxy / localhost:3000 {
    websocket
    transparent
  }
}

http://www.example.com, https://www.example.com {
  redir / https://example.com
}

(madelung) #5

Thanks man, it works.

I understand now what you mean by adding the definition.