# 404 or infinite loop when trying to append prefix to URL

**URL:** <https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [March 11, 2024, 9:44am UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817 "2024-03-11T09:44:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lateparty](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lateparty/32/8377_2.png) [@lateparty](https://community.traefik.io/u/lateparty)\
**Post date:** [March 11, 2024, 9:44am UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/1 "2024-03-11T09:44:24Z")

</div>

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](http://prox.mydomain.com/?mobile=0) not just [prox.mydomain.com](http://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:

```auto
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](http://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 ☹

```auto
  # 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:

```auto
#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 /

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 11, 2024, 10:07am UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/2 "2024-03-11T10:07:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lateparty](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lateparty/32/8377_2.png) [@lateparty](https://community.traefik.io/u/lateparty)\
**Post date:** [March 11, 2024, 10:28am UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/3 "2024-03-11T10:28:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 11, 2024, 12:17pm UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/4 "2024-03-11T12:17:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lateparty](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lateparty/32/8377_2.png) [@lateparty](https://community.traefik.io/u/lateparty)\
**Post date:** [March 11, 2024, 12:32pm UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/5 "2024-03-11T12:32:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 11, 2024, 2:54pm UTC](https://community.traefik.io/t/404-or-infinite-loop-when-trying-to-append-prefix-to-url/21817/6 "2024-03-11T14:54:21Z")

</div>

Can you supply a simple mapping?

```auto
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?
