So i managed to do the following dynamic configuration:
[http]
[http.routers]
[http.routers.redirection-router]
rule = "Host(`test.com`)"
#Defines the service of this router
service = "redirection"
#This Router listens to the entrypoint web and websecure (port 80 and 443)
entrypoint=["web", "websecure"]
#Defines the middleware of this router
middlewares = ["redirection"]
#This is where the actual redirection happens
[http.middlewares]
[http.middlewares.redirection.redirectRegex]
regex = "^http://test.com/(.*)"
replacement = "http://google.com/${1}"
permanent = true
[http.services]
[http.services.redirection.loadbalancer]
[[http.services.redirection.loadbalancer.servers]]
url = "http://test.com:80"
But when i visit test.com Chrome tells me there are too many redirects
The Final Solution was that i first needed to add this lines into my static config:
#Redirection of old projects to our homepage (see ./redirection.toml for configuration)
[providers]
[providers.file]
filename = "/redirection.toml"
Afterwards i createt the file redirection.toml like this:
#This file is used to redirect old project websites (trinex.eu, secom20.eu) to our homepage.
[http.routers]
[http.routers.redirection-router]
rule = "Host(`test.com`)"
#Defines the service of this router
service = "dummy"
#This Router listens to the entrypoint web and websecure (port 80 and 443)
entrypoint=["websecure"]
#Defines the middleware of this router
middlewares = ["redirect"]
[http.middlewares]
[http.middlewares.redirect.redirectRegex]
regex = "(.*)test.com(.*)"
replacement = "http://google.com"
permanent = true
#This Service is completely unnecessary but it if you delete it things will go wrong
[http.services]
[http.services.dummy.loadbalancer]
[[http.services.dummy.loadbalancer.servers]]
url = "localhost"
And now it works perfectly. Hope this might help you if you stumble upon this.
If you already have an Ingressroute then you can add an additional rule that will point example.com to the same backend service used by app.example.com and use the middleware we created above