github.com/steampixel/simplephprouter ↗
This is a simple and small single class PHP router that can handel the whole url routing for your project.
Open this visualization on its own page →
Contributors
8
Lines of Code
141
From
2015-09-10
To
2020-10-16
About steampixel/simplephprouter
Simple PHP Router is a lightweight, single-class PHP router designed to handle URL routing for web projects. It uses regular expressions and anonymous PHP functions to match routes and execute handlers, supporting dynamic path parameters, HTTP method verification (GET, POST, PUT, DELETE, etc.), and special 404 and 405 error routes. The codebase is intentionally minimal and straightforward, making it suitable as a learning resource or boilerplate for custom routing implementations.
The router offers flexible configuration options including case-sensitive routes, trailing slash handling, and multi-match mode where multiple routes can execute for a single request. It supports multiple output methods—echo, return statements, and PHP 7.4+ arrow functions—and can operate from subfolders by setting a custom base path. The project includes example implementations, Docker setup for testing, and Windows IIS compatibility via a web.config rewrite rule. Installation is available through Composer, and the router pairs well with companion projects like simplePHPComponents and simplePHPPortals.
The project targets developers with foundational PHP knowledge, particularly those comfortable with regular expressions, anonymous functions, and file inclusion patterns. While deliberately simple in scope, it provides useful debugging features such as retrieving all registered routes for documentation or test generation purposes.