Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CalicoJack's avatar

Stuck on "Make a PHP Router" episode—Object not found!

Here's my setup as I'm halfway through the lesson. Please note that below I do not have a router.php file in my project because I am not at that stage quite yet:

server: XAMPP 8.2.0 Apache Web Server

IDE: VSCode

My project complete file path is as follows:

Applications -> XAMPP -> htdocs -> controllers (folder), views (folder), index.php, functions.php

My homepage loads just fine at localhost/, but when I navigate to localhost/about, I get Object not found! The requested URL was not found on this server. and I swear everything looks correct! I have paused Jeffrey's video to ensure my code looks exactly like his does in every place... index.php, my controllers, my views, my partials... everything. ChatGPT suggested adding a special .htaccess file to the root directory, but I don't know where to begin with that. Any ideas for success with this one??? My index.php is shared below

<?php

require 'functions.php';

$uri = $_SERVER['REQUEST_URI'];
echo $uri; // this echoes appropriately for the home page "/" but that's it

if ($uri === '/') {
    require 'controllers/index.php';
} else if ($uri === '/about') {
    require 'controllers/about.php';
} else if ($uri === '/contact') {
    require 'controllers/contact.php';
}

?>
0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The issue is that the server is not able to find the requested URL. This can be resolved by creating a .htaccess file in the root directory of the project. The .htaccess file should contain the following code:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]

This code will redirect all requests to the index.php file, which will then handle the routing.

Additionally, it's important to make sure that the Apache mod_rewrite module is enabled. This can be done by uncommenting the following line in the httpd.conf file:

LoadModule rewrite_module modules/mod_rewrite.so

Once the .htaccess file is created and the mod_rewrite module is enabled, the routing should work as expected.

1 like
CalicoJack's avatar

@LaryAI Lary, you beautiful, artificial monster. That worked like a charm—just needed a little encouragement and explanation for that .htaccess file. Thank you!

Please or to participate in this conversation.