A small PHP routing system that maps clean URLs to PHP files.
Built to work well with SPA-style front ends without using a framework.
This project exists because sometimes you just want:
- clean URLs
- predictable file-based routing
- full control over what runs
- no dependencies
All requests are routed through index.php using .htaccess.
Instead of loading full pages, the router returns HTML inside a JSON response.
The front end swaps the content without reloading the page.
Example flow:
/test1
→ index.php?page=test1
→ api/router.php
→ pages/test1.php
→ { html: "<h1>Test Page One</h1>" }
The layout and navigation never reload — only the page content changes.
/
├── index.php
├── .htaccess
├── api/
│ └── router.php
└── pages/
├── home.php
├── test1.php
└── test2.php
-
index.php
App shell and front-end logic -
.htaccess
Handles clean URLs and routes everything through PHP -
api/router.php
Resolves routes, loads page files, and returns HTML as JSON -
pages/
Plain PHP files that output HTML only (no layout)
/→home/home→pages/home.php/test1→pages/test1.php/test2→pages/test2.php- Unknown routes return a themed 404 response
Routes are normalised and restricted to prevent directory traversal or invalid paths.
- Create a file in
pages/
pages/about.php
- Visit it in the browser
/about
That’s it. No config, no registration step.
If a page does not exist or the route is invalid, the router returns:
- a JSON error response
- a themed HTML error view
- a safe status code inside the payload
The error UI is designed to sit inside the app layout, not replace it.
The default front end uses:
- Tailwind CSS
- Alpine.js
- Flowbite
- Font Awesome
You can replace the front end entirely — the router does not depend on it.
Frameworks are great, but sometimes they’re too much.
This project is for:
- internal tools
- small dashboards
- admin panels
- experiments
- learning how routing actually works
If you can read basic PHP, you can understand the whole system.