Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel
我正在尝试使用RESTful控制器.这是我的Route.php
:
I am trying to use RESTful controller. Here is my Route.php
:
Route::resource('test', 'TestController');
Route::get('/', function()
{
return View::make('hello');
});
这是我的TestController.php
<?php
class TestController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return View::make('test.home');
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
我的应用程序路由为localhost/Test/public/
,并显示您已经到达"消息.但是当我尝试localhost/Test/public/test
时,它给了我"Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"
My app route is localhost/Test/public/
and it shows "You have arrived" message. But when I tried localhost/Test/public/test
It gives me "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
这是我的日志:
[2014-05-11 14:29:59] production.ERROR: NotFoundHttpException Route: `http://localhost/Test/public/test` [] []
[2014-05-11 14:29:59] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\wamp\www\test\bootstrap\compiled.php:5289
Stack trace:
#0 C:\wamp\www\test\bootstrap\compiled.php(4663): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 C:\wamp\www\test\bootstrap\compiled.php(4651): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 C:\wamp\www\test\bootstrap\compiled.php(4643): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 C:\wamp\www\test\bootstrap\compiled.php(698): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 C:\wamp\www\test\bootstrap\compiled.php(679): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 C:\wamp\www\test\bootstrap\compiled.php(1136): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 C:\wamp\www\test\bootstrap\compiled.php(7218): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#7 C:\wamp\www\test\bootstrap\compiled.php(7815): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#8 C:\wamp\www\test\bootstrap\compiled.php(7762): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#9 C:\wamp\www\test\bootstrap\compiled.php(10768): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#10 C:\wamp\www\test\bootstrap\compiled.php(640): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#11 C:\wamp\www\test\public\index.php(49): Illuminate\Foundation\Application->run()
#12 {main} [] []
我知道这个问题已经问过很多次了.我经历了许多相关的话题,但无法解决.
I know this question has been asked many times. I had gone through many relevant threads but just can not figure out the solution.
Laravel中的NotFoundHttpException
异常始终表示它无法为特定URL找到 router /strong>.在您的情况下,这可能是您的Web服务器配置,虚拟主机(站点)配置或.htaccess配置中的问题.
A NotFoundHttpException
exception in Laravel always means that it was not able to find a router for a particular URL. And in your case this is probably a problem in your web server configuration, virtual host (site) configuratio, or .htaccess configuration.
您的public/.htaccess应该如下所示:
Your public/.htaccess should look like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
如您所见,第一行IfModule mod_rewrite.c
中存在一个条件,因此,如果未安装或启用mode_rewrite,则所有重写规则都将失败,并且
As you can see there is a condition in the first line IfModule mod_rewrite.c
, so if you don`t have mode_rewrite installed or enabled, all rewrite rules will fail and this
localhost/Test/public/
可以正常工作,但不能这样:
Will work fine, but not this:
localhost/Test/public/test
另一方面,这也应该起作用,因为这是其原始形式:
In other hand, this one should work too, because this is its raw form:
localhost/Test/public/index.php/test
因为Laravel需要对其进行重写才能正常工作.
Because Laravel needs it to be rewritten to work.
请注意,您不应使用/public,您的网址应如下所示:
And note that you should not be using /public, your URLs should look like this:
localhost/Test/
这是另一个线索,表明虚拟主机的文档根目录配置不正确或未指向/var/www/Test/public或应用程序所在的路径.
This is another clue that your virtual host's document root is not properly configured or not pointing to /var/www/Test/public, or whatever path your application is in.
所有这些假设您正在使用Apache 2.
All this assuming you are using Apache 2.