RouteCollection.php中的NotFoundHttpException

时间:2016-07-10 12:09:15

标签: php laravel laravel-5.1

我创建了一个新的laravel 5项目,路由文件如下所示。

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

当我使用http://localhost/mysite/laravel/public/访问它时,它工作正常并转到欢迎页面。但是当我将路由修改为低于http://localhost/mysite/laravel/public/blogs时,会发生错误。

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

错误:

NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

该项目是一个新项目,我没有更改除路线以外的任何文件。这个错误的原因是什么?我正在使用laravel 5.x和XAMPP。我在stackoverflow中阅读了所有类似的问题,但我仍然无法找到答案,请帮忙。 enter image description here

2 个答案:

答案 0 :(得分:2)

您必须设置virtualHost;

# VirtualHost for LARAVEL.DEV
<VirtualHost laravel.dev:80>
    DocumentRoot "C:\xampp\htdocs\laravel\public"
    ServerAdmin laravel.dev
    <Directory "C:\xampp\htdocs\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

并将etnry添加到位于以下位置的hosts文件中:

C:\Windows\System32\drivers\etc

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost

127.0.0.1    laravel.dev

请记住调整路径。

答案 1 :(得分:2)

您还可以通过打开命令提示符运行laravel项目,将工作目录更改为laravel项目文件夹,然后触发命令&#34; php artisan serve&#34;。

现在可以通过 - localhost:8000访问您的laravel项目。

为什么你不能在没有虚拟主机配置的情况下直接从xampp出来的原因是,出于安全原因,laravel应用程序使用公用文件夹作为“root”,除非你将/ public附加到访问URL。 / p>