laravel - 为什么我在 Laravel 中的路线返回 404 错误?

标签 laravel laravel-5

所以在我的 routes.php 文件中我有这个:

Route::get('contact', function() {
   return view('contact');
});

当我访问 domain.com/contact 时,出现返回错误。然而,当我把:
Route::get('/', function() {
    return view('contact');
});

并转到 domain.com 页面出现。知道是什么原因造成的吗?

完整的路由文件:
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('homeIndex');
});

Route::get('contact', function() {
    return view('contact');
});

php artisan route:list 返回:
+--------+----------+---------+------+---------+------------+
| Domain | Method   | URI     | Name | Action  | Middleware |
+--------+----------+---------+------+---------+------------+
|        | GET|HEAD | /       |      | Closure | web        |
|        | GET|HEAD | contact |      | Closure | web        |
+--------+----------+---------+------+---------+------------+

最佳答案

好的,所以我解决了我的问题。如果其他人遇到此问题,请确保在您的服务器上启用了 mod_rewrite。您可以通过转到终端并输入来执行此操作
a2enmod rewrite
然后打字
service apache2 restart
它现在就像一个魅力。

关于laravel - 为什么我在 Laravel 中的路线返回 404 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38733180/

相关文章:

php - 在数据库迁移中添加一个 `tsrange` 列

php - laravel 侦察兵 : How to update index in controller

php - Laravel 5 Collection 的大规模更新

html - 在列中显示照片的问题

Laravel 护照从数据库中获取 token

laravel - 找不到框“laravel/homestead”

php - 从请求中排除 Laravel 特定的值

php - Laravel 从集合中获取一个字段的另一个字段值

mysql - Laravel 5 BETWEEN 查询语法

php artisan 迁移: PDOException could not find driver