Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Trailing Slash Laravel Package

middlewares/trailing-slash

Laravel middleware that normalizes trailing slashes by redirecting URLs to your preferred format, with configurable behavior, query-string preservation, and clean handling of requests that already match.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. The description's framing as a "Laravel/PHP package" is the first thing to correct: this is a framework-agnostic PSR-15 middleware, not a Laravel service provider with a config file. Laravel's HTTP kernel is not PSR-15 native — it uses handle($request, Closure $next) against Illuminate\Http\Request, while PSR-15 uses process(ServerRequestInterface, RequestHandlerInterface): ResponseInterface. Adopting this means adding a PSR-7 implementation plus a PSR-15↔Laravel bridge (or writing a thin adapter class ourselves), so a "dependency-free" marketing claim becomes three or four transitive packages in a Laravel context. Laravel's router is already tolerant of trailing slashes, so the router's behavior is not the problem being solved; the deliverable is a canonicalization redirect for SEO, analytics, and cache-key consistency, not routing correctness.

Integration feasibility. Technically straightforward: a global middleware that inspects the request path, early-returns for /, compares against the configured mode, builds a 301 with the query string preserved, and short-circuits. The real feasibility question is placement. A PSR-15 adapter must run before routing to catch unmatched paths, but running before Laravel's session/StartSession and cookie middleware means the redirect response may not carry session cookies — usually acceptable for a canonical redirect, but it must be verified. PSR-7 messages are immutable, so any request attributes set downstream cannot flow back into the Illuminate request; if other middleware mutates the request (locale, tenant resolution from path prefix), ordering becomes a design decision rather than a drop-in.

Technical risk. Code-level risk is low; ecosystem-level risk is the dominant concern. Signals: 32 stars, unknown/unverified repository, score 0.22, single-maintainer project, one release in 2025. That is a bus-factor and provenance question, not a correctness question. Concrete behavioral risks to validate before adoption:

  • Root and edge paths — /, multi-slash (//about//), percent-encoded segments, and paths with file extensions must not cause loops or double redirects.
  • HTTP methods — a 301 on a POST is silently converted to GET by most clients. Any API surface behind the same middleware stack needs 308 semantics or an exemption, which the package does not offer per the description.
  • Proxy/CDN alignment — if a load balancer or CDN already rewrites slashes, the two layers can fight and produce redirect chains or loops.
  • Signed URLs — Laravel's URL::signedRoute, email verification links, password-reset links, and any HMAC validated over the exact path will fail signature checks when the path is rewritten. This is the highest-severity failure mode for a Laravel deployment.

Key questions for the maintainer/PoC.

  1. Does it exempt / and preserve query strings and fragments exactly?
  2. Does it act on non-idempotent methods, and can the redirect status be configured (301 vs 308) or restricted to GET/HEAD?
  3. Which PSR-15 version does it target (1.x vs 2.x), and which PSR-7 implementations are exercised in CI?
  4. Is there a dry-run/log-only mode, or must we wrap it to observe would-be redirects before enforcing?
  5. Does it account for X-Forwarded-Proto/Host and subdirectory deployments?
  6. What is the maintenance posture — release cadence, issue response time, security disclosure process?

Given the risk profile, the defensible TPM position is: this is a ~50-line behavior, so evaluate it as build-vs-buy against a first-party Laravel middleware, not against nothing. Buy only if it demonstrably survives the questions above; otherwise implement internally and keep the canonicalization policy in our own codebase.

Integration Approach

Stack fit. Suitable for PHP 8.1+ on Laravel 10/11/12 through an adapter, and native for Slim, Mezzio, or custom PSR-15 stacks. If the platform already standardizes on PSR-15 at the edge (Mezzio, RoadRunner/PSR-7 workers), the middleware fits cleanly with no bridging and the calculus changes favorably. Within a pure Illuminate codebase, the bridge is the majority of the work — a poor ratio for a redirect rule.

Migration path. Treat it as a behavior change, not a dependency install. Pre-work: declare the canonical form per host and route group (add vs remove), then fix all emitters first — route()/url() output, sitemaps, canonical tags, internal navigation, marketing links, email templates, partner deep links. Emitting /about/ while enforcing /about guarantees a redirect hop on every internal click. Then enable enforcement in staging behind logging, compare logged paths against the routing table for 404-generating redirects, and only then promote.

Compatibility. Pin the PSR-7 implementation already present in the dependency graph to avoid duplicate message implementations and conversion bugs. Verify compatibility with Octane/RoadRunner/Swoole workers if used (immutable request objects and worker-level state are common sources of subtle breakage). Confirm interaction with Laravel's TrustProxies, HTTPS enforcement, and any existing URL rewriting at the web server (nginx try_files, Apache mod_rewrite) so exactly one layer owns slash normalization.

Sequencing.

  1. Inventory and decide the canonical policy; document exceptions (APIs, webhooks, signed URLs, file downloads).
  2. Remediate emitters and update sitemaps/canonical tags.
  3. Add the adapter + middleware disabled-by-default; deploy to staging.
  4. Enable log-only (wrapper) and diff against the route table and access logs.
  5. Enable for GET/HEAD only in production; monitor 301 volume, crawl stats, and error rates for one to two weeks.
  6. Expand scope, or hand the rule to the CDN/edge once stable to eliminate the extra origin hop.
  7. Revisit the third-party dependency at each dependency audit; if it stays unmaintained, vendor the logic in-house.

Operational Impact

Maintenance. Low surface area, MIT licensed, minimal churn — but low activity cuts both ways: no proactive PHP-version or PSR-standard updates, and a single point of failure if the maintainer steps away. Practical mitigation is version pinning plus a 30-minute in-house reimplementation path documented in the runbook, so the dependency is never load-bearing.

Support. No commercial support. With ~32 stars, community answer density is effectively zero — expect our own team to be the de facto support. Escalation for a redirect bug is "read the source," which is feasible given the size, but should be recorded as an accepted risk in the architecture review.

Scaling. Runtime cost is negligible (string comparison plus one header build). The scaling cost is client- and edge-side: every enforced redirect is an extra round trip for that client, and redirects inflate crawl budget. At meaningful traffic, the rule belongs at the CDN/edge layer with the middleware as a fallback for non-cached and origin-direct traffic. Watch for redirect chains (http→https→canonical, www→apex→canonical) that compound latency.

Failure modes (ordered by blast radius).

  1. Irreversible 301 caching — browsers and CDNs cache 301 aggressively; a mis-set mode is expensive to unwind. Use 302 during rollout.
  2. Signed URL / webhook breakage — any path-sensitive signature or exact-URL webhook comparison fails, producing 403s or silently dropped callbacks.
  3. Redirect loops — root path handling, mixed add/remove configuration across environments, or a proxy already rewriting the path.
  4. Method downgrade — 301 on POST/PUT becomes GET, corrupting API semantics or losing payloads.
  5. Redirect-to-404 — because the middleware runs before routing, a path that no route serves still gets a canonical 301, wasting crawl budget and confusing monitoring.
  6. Cache-key divergence — two URLs for one resource split CDN cache and inflate origin load until the redirect settles.

Ramp-up. Engineering effort is hours; the coordination effort is the real cost. It requires a named owner for the canonical URL policy and a short SEO/analytics sign-off, because the change alters indexed URLs and report dimensions. Rollout should be gated on staging verification of the six failure modes above, with a documented one-flag kill switch (middleware disabled via config) and a plan for clients holding cached 301s.

Bottom line. Low technical risk, high governance risk, moderate SEO upside. Approve a time-boxed PoC that answers the six questions and measures redirect volume in log-only mode; default to an in-house equivalent if the PoC is inconclusive or the package shows no maintenance activity over the next release cycle.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator