kiss-php / router
This is a KISS router and I try to keep it simple.
This package is not auto-updated.
Last update: 2026-05-18 20:26:13 UTC
README
Requirements:
- PHP >7.4
- Composer (vendor autoload)
To install you execute:
composer install ...
If you use Apache, create a .htaccess file next to your index.php file.
RewriteEngine On # Never execute PHP files from public RewriteRule ^public/.*\.php$ index.php [L,QSA,NC] # Serve public non-PHP files directly RewriteCond %{REQUEST_URI} !\.php$ [NC] RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f RewriteRule ^(.+)$ public/$1 [L] RewriteCond %{REQUEST_URI} !^/index\.php$ RewriteRule ^ index.php [L,QSA]
With this setup, public/home.png is available as /home.png, but no .php file inside public/ is served or executed directly.
If you use Nginx, add this inside your server block.
location = /index.php { # Your PHP/FPM config here } location ~ ^/public/.*\.php$ { rewrite ^ /index.php last; } location ~ \.php$ { rewrite ^ /index.php last; } location / { try_files /public$uri /index.php; }
With this setup, public/home.png is available as /home.png, but no .php file inside public/ is served or executed directly.
To start to use add the routes in your index.php file.
require 'vendor/autoload.php'; use Kiss\Http\Router; Router::use('', 'Agrandesr\EasyRouter\Controllers\User'); //Function default main Router::use('get','Agrandesr\EasyRouter\Controllers\User::get'); Router::use('update','Agrandesr\EasyRouter\Controllers\User::update');
If you want to serve files from a folder, use useFolder.
Router::useFolder('img', 'public/images/');
This serves img/logo.png from public/images/logo.png, and img/128x128/logo.png from public/images/128x128/logo.png.
When you use php -S for local development, you can serve public/ from the URL root.
if (in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { Router::useFolder('/', 'public/'); }
This serves styles.css from public/styles.css.
If you prefer to execute a PHP file directly, use execute.
Router::execute('about', '/pages/about.php');
If you want to create relative path you can use brackets.
Router::use('update/{id}','Agrandesr\EasyRouter\Controllers\User::update');
Next, you can use this relative path with the static function getOption.
$id = Router::getOption('id');