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
Base Path Router

Base Path Router Laravel Package

middlewares/base-path-router

Laravel middleware for routing applications from a configurable base path, making subdirectory deployments easier without rewriting route definitions. Helps keep route matching and URL generation consistent.

Deep Wiki
Context7

PSR-15 middleware to assign request handlers based on path prefixes

Frequently asked questions about Base Path Router
What is middlewares/base-path-router used for?
It dispatches requests to different middleware handler stacks based on the application's base path. You register a table of path prefixes, such as /, /admin, or a nested deployment folder, and the router matches incoming requests to the correct pipeline. This keeps base-path logic out of controllers and avoids duplicating route definitions.
How do I install middlewares/base-path-router in a Laravel app?
Install it with Composer using composer require middlewares/base-path-router. Then register the middleware in your Laravel HTTP kernel or a custom pipeline where base-path dispatch should occur. Check the package's Composer constraints before installing to confirm compatibility with your Laravel and PHP versions.
Which Laravel versions does middlewares/base-path-router support?
The package has a framework-agnostic core with Laravel integration, so supported Laravel versions depend on its Composer constraints rather than a hardcoded major version in the router logic. Review the package's composer.json for illuminate/support and PHP requirements. Confirm compatibility with your application's Laravel release before upgrading.
How does longest-prefix matching work in middlewares/base-path-router?
When multiple registered prefixes could match a request, the router selects the most specific one. For example, a request under /admin/users resolves to the /admin pipeline rather than the / pipeline. This makes resolution predictable when you have nested or overlapping base paths.
Is middlewares/base-path-router PSR-15 compatible?
Yes, it provides a PSR-15 compatible MiddlewareInterface implementation. That lets it compose with PSR-7 requests and PSR-15 middleware stacks in addition to Laravel-style pipelines. The core is framework-agnostic.
How do I configure base path prefixes and middleware chains?
You register a prefix table that maps each base path to a dedicated middleware chain. The router then matches incoming request paths against those prefixes. Single-path deployments can rely on zero-configuration defaults instead of maintaining a large table.
Does middlewares/base-path-router help with applications deployed in a subdirectory?
Yes, it is designed for apps served from /, /admin, or nested deployment folders. Instead of hardcoding environment-specific subdirectories, you define the prefix mappings once and let the router select the correct handler stack. This helps keep route matching and URL generation consistent across deployments.
How should I test base-path routing in Laravel?
Dispatch test requests with different path prefixes and assert that the expected middleware chain or handler is invoked. Include cases for overlapping prefixes so longest-prefix matching is covered. In Laravel feature tests, also verify that route matching and URL generation remain correct for subdirectory deployments.
What should I check before using middlewares/base-path-router in production?
Confirm your prefix table handles overlapping and nested paths as intended, since longest-prefix matching determines which pipeline runs. Verify that URL generation and redirects use the same base path assumptions as the router. Also review deployment configuration so subdirectory paths are not duplicated in routes or web server rewrites.
What alternatives should I compare with middlewares/base-path-router?
Compare it with Laravel route groups using a route prefix, web server rewrite rules that strip subdirectories, and other PSR-15 routing middleware. The best choice depends on whether you need prefix-to-pipeline dispatch in middleware or only URL prefixing. For framework-agnostic PSR-7/PSR-15 stacks, a middleware-based router can keep base-path logic centralized.
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