traefik_host_path_rewrite

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

traefik-host-path-rewrite

Traefik (Yaegi) middleware that rewrites the request path from the Host header using a configurable template.

Example (default template): example.com/ueber-uns/landing/example/ueber-uns.

Built for Dokploy: leave Custom Entrypoint off (web / websecure), attach a shared middleware such as host-path@file.

Features

  1. Smart domain extraction — strips ports, lowercases, resolves eTLD+1 with a stdlib-only suffix table (common multi-level TLDs such as .co.uk; Yaegi-safe — no embed / x/net), normalizes tokens to [a-z0-9-].
  2. Configurable path template{domain} placeholder; default /landing/{domain} (the /landing prefix is only a default, change it freely).
  3. Subdomain modes
    • ignore_subdomain (default) — stage.example.comexample
    • include_subdomainstage.example.comstage-example
    • subdomain_as_pathstage.example.com/x/landing/example/stage/x (with default template)
  4. Debug headersX-Original-Host, X-Extracted-Domain, X-Rewritten-Path
  5. Fallback — IP / invalid host → configurable fallbackDomain (default default)

Configuration

Field Default Description
template /landing/{domain} Must contain {domain}. Set any path prefix you need, e.g. /sites/{domain} or /t/{domain}.
subdomainMode ignore_subdomain See modes above
fallbackDomain default Used when Host is not a usable domain

Dokploy / Traefik setup

Static configuration (once)
experimental:
  plugins:
    host-path:
      moduleName: github.com/KundS-dev/traefik-host-path-rewrite
      version: v0.1.1

http:
  middlewares:
    host-path:
      plugin:
        host-path:
          template: /landing/{domain}
          subdomainMode: ignore_subdomain
          fallbackDomain: default
Per service (Dokploy UI)
  1. Host: e.g. example.com
  2. Middlewares: host-path@file
  3. Save (leave Custom Entrypoint disabled)

License

Apache-2.0

Documentation

Overview

Package traefik_host_path_rewrite is a Traefik Yaegi middleware that rewrites the request path from the Host header using a configurable template.

Dependencies are intentionally limited to the Go standard library: Yaegi (Traefik Plugin Catalog) cannot load packages that use //go:embed (e.g. golang.org/x/net/publicsuffix).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(_ context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New creates a new HostPathRewrite middleware.

Types

type Config

type Config struct {
	Template       string `json:"template,omitempty"`
	SubdomainMode  string `json:"subdomainMode,omitempty"`
	FallbackDomain string `json:"fallbackDomain,omitempty"`
}

Config holds the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type HostPathRewrite

type HostPathRewrite struct {
	// contains filtered or unexported fields
}

HostPathRewrite is the middleware handler.

func (*HostPathRewrite) ServeHTTP

func (d *HostPathRewrite) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL