Routing 使用通配符的Laravel路由始终为404
我刚刚开始使用Laravel,我非常喜欢路由的想法,但是我创建的任何带有通配符的路由都会回到Laravel 404路由 这是我的路由文件:Routing 使用通配符的Laravel路由始终为404,routing,wildcard,laravel,Routing,Wildcard,Laravel,我刚刚开始使用Laravel,我非常喜欢路由的想法,但是我创建的任何带有通配符的路由都会回到Laravel 404路由 这是我的路由文件: # This loads fine Route::get('hello', function(){ return 'Hello!'; }); # This gives me a 404 Route::get('hello/(:any)', function ($name) { return "Welcome, $name."; }); Ro
# This loads fine
Route::get('hello', function(){
return 'Hello!';
});
# This gives me a 404
Route::get('hello/(:any)', function ($name) {
return "Welcome, $name.";
});
Route::get( array('/'), function()
{
return View::make('home.index');
});
Event::listen('404', function()
{
return Response::error('404');
});
Event::listen('500', function()
{
return Response::error('500');
});
我也尝试过any
,但没有效果
Route::any('hello/(:any)', function ($name) {
return "Sup, $name?";
});
你知道我为什么会得到404吗
编辑:
我想这是因为我的PHP配置有点参差不齐,没有正确处理类的别名之类的。添加将别名映射到类的帮助器类在大多数情况下都有效。是否启用了Apache重写模块?
我已经在我的Laravel装置上尝试了你的第一条路线,效果很好 对于其他新加入Laravel的人,这是使用可选参数设置路线的方式
Route::get('hello/(:any?)', function ($name = 'default') {
return "Welcome, $name.";
});
是的,我从拉威尔那里得到404,不是阿帕奇。我想这只是因为我很傻,不懂路线。它应该是
(:any?
,并将默认选项传递给匿名函数。谢谢你看!