Problem
My AltoRouter is not routing properly on live server (LAMP), but it's working just fine in localhost (XAMPP). How do I know that the routing part is correct? Because, when I execute GET request to assigned routes, the server returns 500 error:
However, when I execute GET request to non-existent routes, the server returns 404 Not Found response:
I configured .htaccess
:
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /caffemania
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
index.php
<?php
require_once 'vendor/autoload.php';
include_once 'api/validate_token.php';
// Setup for base path of project
$router = new AltoRouter();
$router->setBasePath('/caffemania');
// Main routes
$router->map('GET', '/', function() { require __DIR__ . '/controllers/landing.php'; }, 'landing');
$router->map('GET', '/prijava/', function() { require __DIR__ . '/controllers/landing.php'; }, 'login');
$router->map('GET', '/pocetna/', function() { require __DIR__ . '/controllers/homepage.php'; }, 'homepage');
$router->map('GET', '/lokacije/', function() { require __DIR__ . '/controllers/locations.php'; }, 'locations');
$router->map('GET', '/aparati/', function() { require __DIR__ . '/controllers/machines.php'; }, 'machines');
$router->map('GET', '/izvjestaji/', function() { require __DIR__ . '/controllers/reports.php'; }, 'reports');
$router->map('GET', '/skladiste/', function() { require __DIR__ . '/controllers/warehouse.php'; }, 'warehouse');
// Logout
$router->map('GET', '/logout/', function() {
unset($_COOKIE['jwt']);
setcookie('jwt', '', time() - 3600, '/');
$logout_flag = true;
require __DIR__ . '/controllers/landing.php';
}, 'logout');
// Specific routes
$router->map('GET', '/aparati/[i:id]/', function($id) {
$m_id = $id;
require __DIR__ . '/controllers/machine_details.php';
}, 'machine-details');
$router->map('GET', '/izvjestaji/[i:id]/', function($id) {
$r_id = $id;
require __DIR__ . '/controllers/report_details.php';
}, 'report-details');
// Get the match
$match = $router->match();
// Call closure or throw 404 status
if ($match && is_callable($match['target'])) {
call_user_func_array($match['target'], $match['params']);
} else {
// No route was matched
header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
?>