Here is my basic PHP router.php code:
run();
function run()
{
$uri = explode('?', $_SERVER['REQUEST_URI'], 2);
$routes = [
'/' => function () {
include(VIEWS_PATH . DS . 'accueille' . DS . 'accueille.php');
},
'/auth' => function () {
include(VIEWS_PATH . DS . 'auth' . DS . 'login.php');
},
'/404' => function () {
include(VIEWS_PATH . DS . '404' . DS . '404.html');
},
];
$path = $uri[0];
echo "<pre>$path</pre>";
switch ($path)
{
case '/auth':
case '/':
$routes[$path]();
break ;
default :
$notFoundCallback = $routes['/404'];
$notFoundCallback();
}
}
The problem with this code is when I use "/"
as a router the scripts behave as expected but when I use any other router such as "/auth"
or "/404"
or any other random URI that supposed to redirects to 404 page, I get the Apache 404 page not found.
Here is the index.php code
<?php declare(strict_types=1);
require_once '../config/ini.conf.php';
include(VIEWS_PATH . DS . 'globals' . DS . 'head.php');
include(CONFIG_PATH . DS . 'router.php');
My PHP program is structured as follows:
|_ app
|_ modules
|_ views
|_ 404
|_ 404.html
|_ accuellie
|_ accuellie.php
|_ auth
|_ login.php
|_ globals
|_ controllers
|_ config
|_ ini.conf.php
|_ router.php
|_ public
|_ index.php
I have skipped irrelevant files so the question is not too long here.
I need to clarify that the constants of paths are defined correctly, and accuellie.php
working proves that.
I have tried some Apache configs but I still get the same errors. I also tried to grant permissions for the files but nothing changed.
I have tried some Apache configs but I still get the same errors. I also tried to grant permissions for the files but nothing changed.
site.conf
file I have /var/www/site/public
as DocumentRoot
, and . htaccess
file contains this config: RewriteEngine On