Ben Borgers

How to redirect www subdomain with Caddy

October 17, 2021

If you want your www subdomain (like to redirect to your “bare” or “naked” domain (like, you can tell the Caddy server to do that redirect.

To do this, you’ll edit your Caddyfile, which is the configuration file for Caddy. My configuration file was located at /etc/caddy/Caddyfile on the server.

To edit it using the nano text editor, I ran:

nano /etc/caddy/Caddyfile

Then, I modified the contents to be like this: {
} {
  # Your real site configuration.

The www redirect needs to be above your real site’s configuration, so that the redirect works.

Save that configuration and reload Caddy. Now, the www subdomain will redirect to the appropriate page on your www-less domain!