Skip to content

Site-level request rewriting (replacing Apache RewriteRule) #4

Description

@hugithordarson

Context

Iteration 1 imports Apache vhost files for hostname + cert info but intentionally ignores RewriteRule directives. The only rewriting modulo currently performs is the canonical-hostname redirect (alias → primary) baked into every Site. Anything more sophisticated — path rewrites, conditional redirects, query-string manipulation, header munging — has no expression in modulo's Site model today.

This came up immediately when migrating a real production server: several of the 17 imported vhosts use RewriteRules that aren't pure canonical-host redirects, and there's no way to express them in modulo without writing ad-hoc handler code.

What we need

A way to attach rewriting/redirecting behavior per-Site, in the configuration model rather than in code. Probably:

  • An ordered list of rewrite rules per Site.
  • Each rule: a match condition (host regex / path regex / method / header), an action (redirect 301/302, rewrite path, set header, deny).
  • A small enough vocabulary to express the common Apache patterns without reinventing mod_rewrite.

Apache patterns to support (from the existing deployment)

  • Canonical-host redirect (already done — keep it).
  • Path-prefix redirect (e.g. /old/* → /new/*).
  • Conditional redirect based on User-Agent / host.
  • HTTPS → HTTPS scheme rewriting that survives the proxy hop.

Nice-to-have but not first iteration:

  • Full regex substitution in the destination path.
  • RewriteCond chains.

What we explicitly don't want

  • Embedding mod_rewrite-like syntax. It's a notoriously hard micro-language to reason about; we should land somewhere closer to Caddy's directive-per-line model.
  • Turing-complete rewriting. If someone needs that, they probably need to write a small handler in code anyway.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions