This repository contains a custom Traefik middleware plugin that extracts the path group (normalized path with IDs replaced by labels) into a request header before forwarding it to the upstream service. ID segments (UUIDs, numeric IDs, alphanumeric slugs) are replaced with labels to create a normalized path group. Useful for grouping requests by path pattern rather than specific IDs.
| Field | Type | Default | Description |
|---|---|---|---|
headerName |
string |
x-path-group |
Name of the request header to set |
The following paths will be normalized to the following path group and added to the x-path-group header:
/v1/users/550e8400-e29b-41d4-a716-446655440000/profile -> /v1/users/uuid/profile
/cars/42/bookings -> /vcars/numeric_id/bookings
If you manage Traefik via a helm_release, plugins are registered in the experimental.plugins block of the Helm values, and then activated per-route using a Middleware CRD.
Add the plugin to the experimental.plugins block with the desired plugin and
version.
experimental = {
plugins = {
addPathHeader = {
moduleName = "github.com/syltek/traefik-add-path-group-middleware"
version = "<plugin-version>"
}
}
}Add a Middleware CRD to the extraObjects list in the same Helm release, or deploy it separately as a Kubernetes manifest:
extraObjects = [
{
apiVersion = "traefik.io/v1alpha1"
kind = "Middleware"
metadata = {
name = "<middleware-name>"
namespace = "traefik"
}
spec = {
plugin = {
addPathGroup = {
headerName = "x-path-group"
}
}
}
}
]Reference the middleware in an IngressRoute or Ingress annotation:
# IngressRoute example
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-service
spec:
entryPoints:
- web
routes:
- match: Host(`my-service.example.com`)
kind: Rule
middlewares:
- name: <middleware-name>
namespace: traefik
services:
- name: my-service
port: 8080