# Traefik Gateway API sub path

**URL:** <https://community.traefik.io/t/traefik-gateway-api-sub-path/25162>\
**Category:** Traefik v3 (latest)\
**Tags:** kubernetes-crd\
**Created:** [November 14, 2024, 10:29am UTC](https://community.traefik.io/t/traefik-gateway-api-sub-path/25162 "2024-11-14T10:29:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno99costa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/nuno99costa/32/9564_2.png) [@nuno99costa](https://community.traefik.io/u/nuno99costa)\
**Post date:** [November 14, 2024, 10:29am UTC](https://community.traefik.io/t/traefik-gateway-api-sub-path/25162/1 "2024-11-14T10:29:24Z")

</div>

Hello community.

Looking for some help to use Traefik Kubernetes Gateway API to serve Grafana in a subpath.

I have a working Gateway config which is able to route request correctly to, for example, subdomains. However, I want to use subpaths instead. This presents a challenge, namely that the path forwarding doesn't work as expected.

Using the PathPrefix matcher and URLRewrite filter, I'm able to access Grafana at `random.url/grafana/login`, but accessing Grafana at `random.url/grafana` redirects to `random.url/login`.

```auto
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /grafana
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /

```

I believe that a RequestRedirect filter (see [here](https://gateway-api.sigs.k8s.io/guides/http-redirect-rewrite/#path-redirects)) instead might fix the problem, but doesn't work, and produces an httproute is invalid error.

```auto
  rules:
  - backendRefs:
    - group: ""
      kind: Service
      name: kube-prometheus-stack-grafana
      namespace: kube-prometheus-stack
      port: 80
      weight: 1
    matches:
    - path:
        type: PathPrefix
        value: /grafana
    filters:
      - type: RequestRedirect
        requestRedirect:
          path:
            type: ReplacePrefixMatch
            replacePrefixMatch: /
          statusCode: 302

```

Any idea on how to achieve this without editing configs on Grafana itself? Based on this [tutorial](https://grafana.com/tutorials/run-grafana-behind-a-proxy) from Grafana, it should be possible.

---

<div class="post-metadata">

**Author:** ![aoas](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/aoas/32/9585_2.png) [@aoas](https://community.traefik.io/u/aoas)\
**Post date:** [November 18, 2024, 6:15pm UTC](https://community.traefik.io/t/traefik-gateway-api-sub-path/25162/2 "2024-11-18T18:15:07Z")

</div>

It looks to me like your first example is definitely the right direction, but is missing some of the config you would need. I don't see that it is specifying any backend grafana service to send the requests to.

Maybe you had such config and just didn't quote it, but if not, you'd want an `httproute` rules section much like your original, but with a `backendRef` pointing those matched requests to grafana service:

```auto
rules:
    - matches:
        - path:
            type: PathPrefix
            value: /grafana
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
      backendRefs:
        - name: my-grafana-svc
          weight: 1
          port: 80

```
