Add your code in the post, don't link to images.
You place the code inside three back ticks ```
//Code goes here
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello there, i'm trying to make a PHP router but I get an error, homepage is working fine but when I try to navigate to other pages I get this error: https://ibb.co/9p38Bs3
this is index.php :
require "functions.php";
$uri = $_SERVER['REQUEST_URI'];
if ($uri === '/newphp/') {
require 'controllers/index.php';
}
else if ($uri === '/about') {
require 'controllers/about.php';
}
else if ($uri === '/contact') {
require 'controllers/contact.php';
}
these are the page links :
<a class="list-group-item list-group-item-action <?= urlIs('/newphp/') ? 'list-group-item-dark' : 'list-group-item-light' ?> p-3" href="/newphp/">Home</a>
<a class="list-group-item list-group-item-action <?= urlIs('/about.php') ? 'list-group-item-dark' : 'list-group-item-light' ?> p-3" href="/about">About</a>
<a class="list-group-item list-group-item-action <?= urlIs('/contact.php') ? 'list-group-item-dark' : 'list-group-item-light' ?> p-3" href="/contact">Contact</a>
and this is the file structure: https://ibb.co/t85zt9g i know it's so basic and not best practise but i need it to work at least i think the problem it that it's not reading the request URI correctly, idk might be wrong thought, maybe that's why i haven't solved this issue yet. thanks in advance
Problem Solved, You need to add this rule to your apache2 config inside the <Directory> ruleset.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [QSA,L]
</IfModule>
if your project is in a separate folder you need to include the path next to index.php in the code above so in my case it was newphp/index.php
Please or to participate in this conversation.