我在XAMPP 5.6.15中使用Laravel 5.3.28,PHP 5.6.15
在我的文件 routes \ web.php 中我添加了
Route::get('/about', 'DefaultController@about');
(控制器,方法和视图存在)
php artisan route:list return
+--------+----------+------------+------+----------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------+------+----------------------------------------------+--------------+
| | GET|HEAD | / | | App\Http\Controllers\DefaultController@home | web |
| | GET|HEAD | about | | App\Http\Controllers\DefaultController@about | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
+--------+----------+------------+------+----------------------------------------------+--------------+
当我尝试浏览Not Found Exception时会引发。在论坛中查找错误我理解这是由于Laravel或 .htaccess 文件的配置不正确。 我不明白如何正确解决问题以及为什么在documentation中没有提到这个文件的需要。 感谢所有人的帮助或建议。
更新
此处按要求提供错误消息
RouteCollection.php第161行中的NotFoundHttpException:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
答案 0 :(得分:1)
正如我在对原始问题的评论中所写,我在 public 文件夹中找到了 .htaccess 文件。 我以这种方式修改规则
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mylaravel/public/ #----> ADDED THIS
RewriteRule ^(.+)$ index.php/$1 [QSA,L] #----> TWO ROW
# RewriteRule ^ index.php [L] #----> INSTEAD OF THIS
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
通过这种方式URL:
使用正确的路线。