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
Laravel Trailing Slash

Laravel Trailing Slash Laravel Package

gnahotelsolutions/laravel-trailing-slash

Laravel middleware that normalizes trailing slashes on incoming URLs, redirecting requests to your preferred format (with or without a trailing slash) through configurable, SEO-friendly redirects. Easy to install and customize for cleaner, consistent routes.

View on GitHub
Deep Wiki
Context7

🔌 End your Laravel project routes with trailing slash

Frequently asked questions about Laravel Trailing Slash
How do I install gnahotelsolutions/laravel-trailing-slash in a Laravel app?
Install it with Composer using composer require gnahotelsolutions/laravel-trailing-slash. The package supports Laravel package auto-discovery, so the service provider is registered for you, but you still need to register the middleware in your HTTP kernel or route group and publish the config file with the vendor:publish command. After publishing, set your preferred slash format and exclusions, then verify behavior on a staging environment before enabling it globally.
Does the middleware add trailing slashes to routes or remove them?
The package normalizes URLs to a preferred format, which you define in the published config file, so it can either append or strip the trailing slash depending on your choice. Requests that do not match the canonical form are redirected rather than rewritten in place. Pick one format for the whole application and keep it consistent across sitemaps, canonical tags, and internal links.
Which Laravel and PHP versions does this package support?
Support depends on the version you install, so check the composer.json constraints and the release history on Packagist before committing to it. The package is a thin HTTP middleware with no database or external service dependencies, so it typically works on any modern Laravel stack that matches its declared constraints. Pin the exact version in composer.json so an unrelated dependency update cannot silently change URL behavior.
Does the middleware redirect with a 301 or a 302 status code?
The redirect status is part of the package's configurable redirect behavior, so confirm the default in the config file before you enable it in production. Prefer temporary redirects while you are still validating the policy, because browsers and CDNs cache 301s aggressively and a wrong canonical form can be painful to undo. Only switch to permanent redirects once the URL inventory, exclusions, and sitemap have been reconciled.
How do I exclude API routes, webhooks, and health checks from the trailing slash redirect?
Exclusions are configured through the package's published config file, where you can list the paths or patterns that should bypass normalization. Exclude anything non-idempotent or machine-consumed, such as API endpoints, webhook receivers, and uptime health checks, since clients on the other side may not follow redirects. Review access logs to build a realistic exclusion list rather than guessing.
Will the trailing slash redirect break signed URLs like email verification or password reset links?
Laravel signed URLs include a signature computed over the full path, so if the middleware changes the path before the signature is verified, the link will fail validation. Exclude the signed routes, or generate the signed URLs in the canonical slash format so no redirect is needed. Test verification and password reset flows end to end on staging before rolling out.
Does it rewrite URLs generated by route() and url(), or only redirect inbound requests?
This package works in the HTTP middleware layer, so its job is to normalize inbound requests and redirect them to the canonical form. It does not change what route(), url(), pagination, or asset helpers output, which means your application code should already generate canonical URLs. If you need outbound rewriting as well, that is a separate and much more invasive concern.
Can I disable the trailing slash middleware in production without deploying?
The middleware reads its behavior from the published config file, so you can wire an environment variable into that config as a kill switch and turn normalization off by clearing config cache. Confirm the exact toggle in the package's config and test it on staging first. Having an off switch matters because a slash policy change affects every URL the application serves.
Will this middleware conflict with nginx, Apache, or a CDN that already normalizes slashes?
Yes, that is the most common failure mode for this class of package: two layers both trying to own the canonical URL can produce redirect loops or inconsistent results. Decide on exactly one owner of the slash policy, usually the edge, and disable the other. If you keep the middleware, make sure the web server and CDN pass the original path through unchanged.
How do I test the trailing slash middleware in Laravel?
Write feature tests that assert a request to the non-canonical URL returns the expected redirect status and Location header, and that the canonical URL returns 200. Add explicit tests for excluded paths such as API routes and health checks, plus a signed URL flow if your app uses one. Running these against a realistic route table in CI catches regressions when you upgrade Laravel or the package.
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.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console