Redirect Configuration#
Dokploy's advanced application settings support regex-based HTTP redirect rules backed by Traefik's redirectRegex middleware. Each redirect stores three fields — regex, replacement, and permanent — and is applied at the Traefik layer, so no application code changes are needed.
Data Model#
Redirects are persisted in the redirects table . Key columns:
| Field | Type | Purpose |
|---|---|---|
regex | string | RE2-compatible regex to match incoming URLs |
replacement | string | Replacement URL; uses ${N} capture group syntax |
permanent | boolean | true → HTTP 301; false → HTTP 302 |
uniqueConfigKey | serial | Used to generate a unique Traefik middleware name per redirect |
applicationId | FK | Associates the redirect with its application |
Capture Group Syntax#
The replacement field references regex capture groups using ${N} notation (e.g., ${1} for the first capture group). This is Traefik's RE2 syntax — do not use $${N} (double-dollar); that was a bug that was fixed in PR #717.
Built-in presets :
| Preset | Regex | Replacement |
|---|---|---|
| Redirect to www | ^https?://(?:www.)?(.+) | https://www.${1} |
| Redirect to non-www | ^https?://www.(.+) | https://${1} |
Traefik Integration#
Each redirect rule is stored as a named Traefik middleware: redirect-{appName}-{uniqueConfigKey} . The redirect utility (packages/server/src/utils/traefik/redirect.ts) provides three functions — createRedirectMiddleware, updateRedirectMiddleware, and removeRedirectMiddleware — that write the configuration directly to Traefik's dynamic config (supports both local and remote server deployments via serverId).
The resulting Traefik middleware block looks like:
http:
middlewares:
redirect-{appName}-{key}:
redirectRegex:
regex: <your regex>
replacement: <your replacement>
permanent: true|false
Redirect rules are not applied to preview domains — createRouterConfig() skips redirect middlewares when domainType === "preview" .
UI Entry Points#
show-redirects.tsx— Lists all redirects for an application; displays regex, replacement, and permanent status with edit/delete actions.handle-redirect.tsx— Modal dialog for creating or editing a redirect. Includes preset selector, regex/replacement inputs, and permanent toggle. Validated with Zod .
Both are located at apps/dokploy/components/dashboard/application/advanced/redirects/.
API / Service Layer#
The tRPC router at apps/dokploy/server/api/routers/redirects.ts exposes create, one, update, and delete endpoints . The service layer at packages/server/src/services/redirect.ts orchestrates DB writes and Traefik config updates atomically — e.g., createRedirect persists the record then calls createRedirectMiddleware.
Key Gotchas#
- Capture group syntax is
${1}, not$${1}. Double-dollar was a preset bug, now fixed . - Regex dialect is RE2 (Traefik's engine) — no lookaheads or backreferences.
- Middleware names are stable across updates because they use
uniqueConfigKey(a serial, not the redirect UUID), preventing orphaned Traefik configs on rename. - Preview subdomains do not inherit redirect rules from the parent app .