AltoRouter не выполняет маршруты, но работает на локальном хосте (LAMP) - PullRequest
1 голос
/ 18 марта 2019

Задача

My AltoRouter неправильно маршрутизируется на работающем сервере (LAMP), но в localhost (XAMPP) работает нормально. Как я узнаю, что часть маршрутизации верна? Потому что, когда я выполняю запрос GET для назначенных маршрутов, сервер возвращает ошибку 500:

500 Internal Server Error

Однако, когда я выполняю запрос GET для несуществующих маршрутов, сервер возвращает 404 ответ Not Found:

404 Not found

Я настроил .htaccess:

.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>

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');
}
?>
...