V2: Redirects not working no matter what I try

1. My Caddy version (caddy version):

v2.0.0-beta.18

2. How I run Caddy:

systemctl

a. System environment:

systemd + ubuntu 18.06

b. Command:

the systemd from the documentation

c. Service/unit/compose file:

{
  "admin": {
    "listen": ":26450"
  },
  "apps": {
    "http": {
      "servers": {
        "redirects": {
          "automatic_https": {
            "disable_redirects": true
          },
          "listen": [
            ":80",
            ":443"
          ],
          "routes": [
            {
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "close": true,
                          "handler": "static_response",
                          "headers": {
                            "Location": [
                              "http://google.com/{http.request.uri}"
                            ]
                          },
                          "status_code": 302
                        }
                      ]
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": [
                    "redirect1.tk"
                  ]
                }
              ],
              "terminal": true
            }
          ]
        }
      }
    },
    "tls": {
      "automation": {
        "on_demand": {
          "rate_limit": {
            "burst": 10,
            "interval": "10m"
          }
        },
        "policies": [
          {
            "issuer": {
              "ca": "https://acme-staging-v02.api.letsencrypt.org/directory",
              "email": "me@stevenverbeek.com",
              "module": "acme"
            },
            "on_demand": true
          }
        ]
      }
    }
  }
}

3. The problem I’m having:

I am trying to redirect everything from http://redirect1.tk to http://google.com so if I typed in

http://redirect1.tk/gdfgdf?hgdhf=hi I would go to http://google.com/gdfgdf?hgdhf=hi

however I can’t even get a simple redirect working, it just returns a blank 200.

4. Error messages and/or full log output:

There is no errors.

5. What I already tried:

I’ve tried subroute handler (see above), I’ve tried static_response as the main handler (basically just get rid of subroute and replace it with the static_response handler), nothing seems to redirect. I am not sure why my JSON config is wrong?

6. Links to relevant resources:

I’ve tried everything I can think of in the documentation.

Just for kicks, try replacing your entire config with asldkfjls and then load it, and see what the logs/errors say.

2 Likes

I’m just not fully there today, it ended up being that my match host was the wrong domain.

1 Like

Ah… this is why we basically require to not change/redact configs when asking for help. Glad you fixed it.