How PHP routing works without a database

How PHP routing works without a database

A modern CMS doesn't need a database. With pure PHP and a well-structured index.php you can build a complete routing system that reads content directly from the filesystem.

The router in three lines

The principle is simple: every request hits index.php, the slug is extracted from the query string, the parser looks for the matching file in content/.

$slug = preg_replace('/[^a-z0-9\-\/]/', '', $_GET['page'] ?? 'home');
$file = CONTENT_PATH . '/' . $slug . '.html';
if (!file_exists($file)) { http_response_code(404); }

Advantages over WordPress

  • Zero external dependencies
  • No database to configure
  • Deploy = copy files
  • Performance: <10ms per response

The system scales naturally: adding a blog category means creating a folder. Adding a language means copying the /it/ folder and translating lang.json.