我的 AltoRouter 在实时服务器(LAMP)上无法正确路由,但是在localhost(XAMPP)中工作正常。我怎么知道路由部分是正确的?因为,当我对分配的路由执行GET请求时,服务器返回500错误:
但是,当我对不存在的路由执行GET请求时,服务器返回404 Not Found响应:
我配置了.htaccess
:
<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>
<?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');
}
?>