I'm trying to implement routes in php.
.htaccess is configured.
The following works at the base directory in the routes.php file.
$request = $_SERVER['REQUEST_URI'];
$version = '2_0_2';
switch ($request) {
case '/' :
require __DIR__ . '/bonify'. $version . '/app/index.php';
break;
case '' :
require __DIR__ . '/bonify'. $version . '/app/index.php';
break;
case '/bonify' :
require __DIR__ . '/app/index.php';
break;
default:
http_response_code(404);
require __DIR__ . '/views/404.php';
break;
}
However, when the /bonify2_0_2/app/index.php
file is accessed from the url root it wants to include the routes.php file.
I try to include in the /bonify2_0_2/app/index.php
file include('route.php');
this puts it into an infinite loop.
I try to include in the /bonify2_0_2/app/index.php
file include('header.php');
which is located in /bonify2_0_2/app/
and it works.
I try to include in the /bonify2_0_2/app/index.php
file include('../../../route.php');
and it failed to open stream:
.
Clearly I'm not quite understanding how routes work, I assume everything is called/served from the url route directory and everything is relative to that?
Thanks for pointers.