// Main router for the Olive Constructors site. All requests are routed through // this script by the `.htaccess` rewrite rules. It resolves the requested // slug to a page file under `pages/` and surrounds that content with a // consistent header and footer template. If an unknown slug is requested, // a 404 status is sent but the home page is displayed. // Read the slug from the rewritten URL. Trim leading/trailing slashes for // consistency. When no slug is present (e.g. visiting the root URL) default // to the home page. $slug = isset($_GET['slug']) ? trim($_GET['slug'], '/') : ''; // Map slugs to PHP content files. The files contain only the content // section (`#Content`) and any page‑specific scripts; they do not include // `` or `
` tags. Those are provided by the header and footer // templates. $pageMap = [ '' => 'pages/home.php', 'home' => 'pages/home.php', 'projects' => 'pages/projects.php', 'contact' => 'pages/contact.php', ]; // Determine the file to include based on the slug. Unknown slugs result in // a 404 status but fall back to the home page content. if (array_key_exists($slug, $pageMap)) { $contentFile = $pageMap[$slug]; } else { http_response_code(404); $contentFile = 'pages/home.php'; // Adjust slug so that templates know the current page for asset loading $slug = 'home'; } // Include the header template. It expects `$title` and `$slug` variables // (which may be defined in the page file) but will still render if they // aren't set. `$slug` is passed explicitly to the header for conditional // asset loading (e.g. Leaflet on the contact page). require 'templates/header.php'; // Include the requested content file if it exists; otherwise display a basic // error message. The page file should set `$title` and `$slug` as needed. if (file_exists($contentFile)) { include $contentFile; } else { http_response_code(404); echo '