How to migrate Go projects to a new domain using Caddy


I recently migrated from to, including a Forgejo instance. I have a number of projects, including many Go projects. I searched for a way to redirect to a new domain, while still allowing go get commands to work when referencing the old domain. I found this thread which provides an example of how to redirect a single package. The snippet in this guide redirects all packages on a domain.

Add the following to your Caddyfile, replacing with your old domain and with your new domain: {
  route * {
    @goget query go-get=1
    respond @goget `<meta name="go-import" content="{host}{path} git{path}">`

This will not only redirect all normal requests from the old domain to the new domain, it will also redirect go get requests in a way that allows commands using the old domain to continue to work.