所以在我的 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/