【问题标题】:Laravel - doesn't work routingLaravel - 路由不起作用
【发布时间】:2016-11-05 06:35:31
【问题描述】:

我的本​​地主机上有 Laravel(如果重要的话,在 Ubuntu 上)。

Route::get('/', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('layouts/tasks', [
        'tasks' => $tasks
    ]);
});

我有这样的路线,它可以在 localhost/public/ 上运行

但是如果我尝试使用这样的路由创建新页面,例如 localhost/public/test:

Route::get('/test', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('layouts/tasks', [
        'tasks' => $tasks
    ]);
});

返回:

404 (The requested URL /public/test was not found on this server.) 

另外,我尝试了/test/test/public/test,但这些都不起作用。

【问题讨论】:

  • 您使用的是 Apache 还是 NGINX?您应该首先解决您的 /public 问题。
  • 您是否启用了mod-rewrite

标签: php laravel ubuntu routing http-status-code-404


【解决方案1】:

制作另一条路线并简单地放入一个返回语句以检查它是否有效。如果你得到另一个 404,你的 .htaccess 文件可能没有生效。

您需要在虚拟主机中为 DocumentRoot 启用 AllowOverride All。

类似的东西:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

只需将您的 AllowOverride 更改为 All 或添加它。

【讨论】:

    猜你喜欢
    • 2015-01-26
    • 2015-03-13
    • 2017-10-31
    • 2019-11-03
    • 2018-08-01
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多