Building a Simple PHP Router Without Frameworks

You don’t need a framework to build clean routing.

🔹 Basic Router

<?php
$request = $_SERVER['REQUEST_URI'];

if ($request == '/') {
    echo "Home Page";
} elseif ($request == '/about') {
    echo "About Page";
} else {
    http_response_code(404);
    echo "404 Not Found";
}

🔹 Clean URLs (.htaccess)

RewriteEngine On
RewriteRule ^(.*)$ index.php [L]

🔹 Why This Matters

  • Full control
  • Lightweight apps
  • Better understanding of backend logic

Leave a comment

Your email address will not be published. Required fields are marked *