404 or infinite loop when trying to append prefix to URL

Hello,

So I've had a fair bit of playing around with traefik and starting to get my head around things but attempting to troubleshoot this with GPT-4 and Claude 3 kept me going in circles.

I am currently running Proxmox and while I can get Traefik to reverse proxy me to the Web GUI just fine, I want the redirect to be prox.mydomain.com/?mobile=0 not just prox.mydomain.com. All attempts at trying to get this to happen have been fraught. In another environment where I'm using nginx I do the same thing for my Synology DSM re-route and it looks like this:

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name dsm.myotherdomain.com;
    return 301 https://syno.myotherdomain.com/?forceDesktop=1;
}

For Traefik I have tried pathPrefix (just got a 404) and I tried a variety of middleware regex and path appends suggested by the LLMs but they all resulted in weird infinite loops where the url would come out to be prox.mydomain.com?/mobile=0?mobile=0?mobile=0?mobile=0?mobile=0?mobile=0?mobile=0 repeated.

Here are my relevant configs from my dynamic.toml. Any help or suggestions would be greatly appreciated as this works so easily in nginx :frowning:

  # Proxmox
  [http.routers.proxmox-service]
    rule = "Host(`prox.mydomain.com`,`proxmox.mydomain.com`)"
    service = "proxmox-service"
    entryPoints = ["websecure"]
    [http.routers.proxmox-service.tls]
      certresolver = "myresolver"
      domains = [
        { main = "*.domain.com" }
      ]

  # HTTP->HTTPS
  [http.routers.http-catchall]
    rule = "HostRegexp(`{any:.*}`)"
    entryPoints = ["web"]
    middlewares = ["redirect-https"]
    service = "noop"

  # Proxmox service pointing to your server's IP and port
  [http.services.proxmox-service.loadBalancer]
      serversTransport = "insecureskipverify"
    [[http.services.proxmox-service.loadBalancer.servers]]
      url = "https://192.168.32.2:8006"

  # noop service
  [http.services.noop.loadBalancer]
    [[http.services.noop.loadBalancer.servers]]
      url = "http://192.168.0.0"

[http.serversTransports]
  [http.serversTransports.insecureskipverify]
    insecureSkipVerify = true

[http.middlewares]
 # HTTP->HTTPS
 [http.middlewares.redirect-https.redirectScheme]
        scheme = "https"

Editing to include the suggestions from the LLMs - This was repeated when I asked can't Traefik do a simple 301 redirect like nginx? And they gave me this suggestion:

#Add this middlewares to http.routers
  middlewares = ["prox-redirect-with-query"]

# Middleware to redirect to the desired URL with ?mobile=0
[http.middlewares.prox-redirect-with-query.redirectregex]
  regex = "^https?://(prox|proxmox)\\.mydomain\\.com(.*)"
  replacement = "https://${1}.mydomain.com/?mobile=0${2}"
  permanent = true

And again when I try that I get the infinite appending of ?mobile=0 to the end of the url after the /

What do you want to achieve? When do you want the redirect (to attach a query parameter?), when not?

Any time I enter the URL. It effectively acts as a persistent bookmark. I always want to have ?mobile=0 included in the path.

What do you mean by that? You call the URL and always add the query parameter? What if the GUI itself has a link with a query parameter? You would still add it?

Based on the logic of the application there is no known way to trigger that parameter through regular use. It is a flag that can be added by the user to force web GUI and not the crippled and effectively useless mobile GUI.

Can you supply a simple mapping?

example.com -> example.com?m=1
example.com/abc -> example.com/abc?m=1
example.com?b=2 -> example.com?b=2&m=1

And you want a redirect sent back to the client or change the forward request to the target service?