Skip to content

Redirects and Static Responses

Return redirects or fixed local responses without forwarding the request to an upstream service.

Use This When

Use redirects for host/path migrations. Use static responses for maintenance pages, health probes, or deliberate sink routes.

Prerequisites

  • A listener that receives the public request.
  • A clear host/path match so the redirect or static route does not catch unrelated traffic.

Steps

  1. To redirect a whole host, open Proxy -> Routes, select Add Route, and create:

    FieldValue
    Listenerpublic-https
    Priority10
    Host patternold.example.com
    Path prefix/
    ActionRedirect
    ModeExternal origin
    Targethttps://new.example.com
    Status308
    Preserve path suffixOn
    Preserve queryOn

    This sends:

    text
    https://old.example.com/docs?a=1 -> https://new.example.com/docs?a=1
    p2pstream Edit Route drawer showing an external-origin redirect with status, path-suffix, and query controls
    The route drawer keeps redirect mode, target, status code, path-suffix preservation, and query handling with the match that triggers it.
  2. To redirect a path on the same host, use same-host path mode:

    FieldValue
    Host patternapp.example.com
    Path prefix/old
    ModeSame host path
    Target/new
    Status302
  3. To serve a static maintenance response, open the matching route's Edit action under Proxy -> Routes, then select Add Target and configure a static target:

    FieldValue
    Namemaintenance
    TypeStatic
    Status503
    BodyMaintenance in progress
    EnabledOn

    Static targets also support reusable Generic body templates and response headers such as Content-Type and Retry-After through the public configuration API. The redesigned route drawer retains existing template and header values but currently exposes only the inline Body control. Create reusable bodies under Templates, then use the management API when you need to attach one or configure static-response headers until those drawer controls are restored.

    p2pstream Edit Route drawer showing a static target with status, inline body, weight, priority group, and enabled controls
    A static target returns directly from p2pstream. The visible route drawer controls its status and inline body for deliberate local responses such as maintenance pages, probes, or temporary sink routes.
    p2pstream Edit Response Template drawer showing a generic-body template editor and sandboxed preview
    Generic response templates centralize reusable bodies for static targets, rate-limit responses, and WAF block responses while each caller keeps control of status and headers.
  4. Give that route a lower priority number than the normal app route:

    FieldValue
    Priority1
    Host patternapp.example.com
    Path prefix/
    Targetmaintenance

Verification

Run:

bash
curl -I https://old.example.com/docs?a=1
curl -i https://app.example.com/

Redirect routes should return 301, 302, 307, or 308. Static routes should return the configured status, body, and headers.

Troubleshooting

SymptomCheck
Redirect target rejectedSame-host targets must be root-relative paths; external-origin targets must be HTTP/HTTPS origins.
Wrong route winsLower priority numbers run first.
Static route affects all trafficNarrow host/path match or disable the route after maintenance.
API-configured template rejectedStatic targets can only use generic body templates.

Next Steps

Operations documentation for self-hosted p2pstream deployments.