dongtuoleng8624 2019-03-17 23:30
浏览 73

AltoRouter不执行路由,但它在localhost(LAMP)中工作

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:

500 Internal Server Error

However, when I execute GET request to non-existent routes, the server returns 404 Not Found response:

404 Not found

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');
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
    • ¥15 NAO机器人的录音程序保存问题
    • ¥15 C#读写EXCEL文件,不同编译
    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符