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

hassanshahzadaheer's avatar

Object Not found (The PHP Practitioner episodes-17)

HI!

I have still a problem with the document root I applied all the solution, also change my operating system, completely remove XAMPP and install Apache & MySQL locally this method not work for me and then I reinstall xampp then try to run the app but noting gets change.

Now the home page loaded but when I visited any link it shows me this error

`` Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404 localhost Apache/2.4.37 (Unix) OpenSSL/1.0.2q PHP/7.1.26 mod_perl/2.0.8-dev Perl/v5.16.3 ``

here are those link in which I define my problem

https://laracasts.com/discuss/channels/requests/the-php-practitioner https://stackoverflow.com/questions/55365071/problem-with-redirect-to-other-pages-using-uri

0 likes
16 replies
Snapey's avatar

in this code

$uri = (substr($_SERVER['REQUEST_URI'],10));

what does 10 represent? Is it removing the domain from the url? if so, you may need to change it for your use case

hassanshahzadaheer's avatar

@SNAPEY - I remove it and set as the author code

class Request { public static function uri() { return trim($_SERVER['REQUEST_URI'], '/'); } }

but nothing gets change now the index page also shows the

jlrdw's avatar

@HASSANSHAHZADAHEER - To understand this better you really need to go to the PHP manual and study how

$_SERVER['REQUEST_URI']

Works.

Using the code from the tutorial is fine but you need to begin to understand how this stuff works.

Jeffrey is basically getting a part of the uti to use for a request.

Your server string is different so you need to figure out what to put there instead of a 10.

But again look this stuff up to study it better.

I have written routers myself and have been a contributor to another framework, but it's extremely hard teaching these Concepts in a forum post.

hassanshahzadaheer's avatar

@JLRDW - now show me this Fatal error: Uncaught Exception: No route defined for this URI. in /opt/lampp/htdocs/basicPHP/core/Router.php:27 Stack trace: #0 /opt/lampp/htdocs/basicPHP/index.php(6): Router->direct('/basicPHP/') #1 {main} thrown in /opt/lampp/htdocs/basicPHP/core/Router.php on line 27

hassanshahzadaheer's avatar

@JLRDW - could you please give me the exact piece of code that I apply to run my project I will very thankful to you. This error stuck my life

munazzil's avatar

Are you using codeigniter or Laravel, if then what is the version of that?

Snapey's avatar

is /basicPHP/ part of the URL you are typing for your site?

hassanshahzadaheer's avatar

@SNAPEY - I think no because I also try to update my routers.php class

<?php

$router->define([
    '' => 'controllers/index.php',
    'about' => 'controllers/about.php',
    'about/culture' => 'controllers/about-culture.php',
    'contact' => 'controllers/contact.php'
]);

with

  <?php

  $router->define([
      'basicPHP/' => 'controllers/index.php',
      'basicPHP/about' => 'controllers/about.php',
      'basicPHP/about/culture' => 'controllers/about-culture.php',
      'basicPHP/contact' => 'controllers/contact.php'
  ]);

hassanshahzadaheer's avatar

Hi! dear I re-write the code and experience on the

$_SERVER['REQUEST_URI'] 

that my pages do not change it is still on the root directory which is re-test let me show the image of my result page

this is about/culture page now I understand is that must be the re-test/about/culture but the request_uri not return the right path

https://prnt.sc/o0wv8f

can you please now figure out what is the problem

thank you so much

hassanshahzadaheer's avatar

Hi! Dear all thank you so much for your help I have resolved my issue after a long time.

thank you

Snapey's avatar

probably because the project is running in a sub-folder and the length of the domain and the sub-folder was not being taken into account.

hassanshahzadaheer's avatar
Level 5

@JLRDW - yes why not

I made a change in routes.php, htaccess & request.php files

In the start, I place the root directory routes.php

<?php

$router->get('re-test','controllers/index.php');
$router->get('re-test/about','controllers/about.php');
$router->get('re-test/about/culture','controllers/about-culture.php');
$router->get('re-test/contact','controllers/contact.php');
$router->get('names','controllers/add-name.php');

.htaccess

RewriteEngine On
RewriteBase /re-test/
AddType text/css .css
AddType text/javascript .js
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^.*$ index.php [END]

Request.php

trim($_SERVER['REQUEST_URI'], '/' );
1 like

Please or to participate in this conversation.