Redirect FQDN to another FQDN

I've been looking at middleware redirectRegex schemes in the docs, in the forums and on various blogs, but for whatever reason I can't seem to get my setup working the way I need it to. It appears this shouldn't be that complicated, but I'm clearly not understanding something.

What I'm after is rather simple (I think). I have an app running running on app.example.com and I need to sunset that domain and FQDN. So, I want to redirect app.example.com to app.example.net.

I've tried to put in a redirect in various places, including my config.yml file, like so:

http:

  middlewares:

    https-only:
      redirectScheme:
        scheme: https
        permanent: true

    ...

    app-redirect:
      redirectRegex:
        regex: "^http://app.example.com/(.*)"
        replacement: "https://app.example.net/"
        permanent: false

I thought this would be all I needed. I've tried some iterations of other regexes, but none have made any difference. The only thing that happens is that if I go to http://app.example.com, I get redirected to https://app.example.com.

If anyone can tell me what I'm doing wrong, I'd greatly appreciate it.

Thanks in advance.

If you redirect to https first, you should probably use https in regex.

Thanks for the input @bluepuma77. Yeah, that makes sense, and I think I had actually tried that before too. I did try it again, but same thing happens. The only redirection that happens is from http to https on the same domain/FQDN. The redirection to the new domain doesn't happen. I also tried adding a second redirect, like so:

app-redirect-https:
      redirectRegex:
        regex: "^https://app.example.com/(.*)"
        replacement: "https://app.example.net/"
        permanent: false

... but that doesn't do anything either.

Doc can be so helpful :wink:

When defining a regular expression within YAML, any escaped character needs to be escaped twice: example\.com needs to be written as example\\.com .