Php laravel将未定义的url路由到特定控制器

Php laravel将未定义的url路由到特定控制器,php,laravel,laravel-5,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.2,在Laravel5.2中,我想将所有未定义的url路由到一个特定的控制器 我正在开发类似CMS的功能,我想要这个东西 Route::get('profile', 'Controller@profile'); Route::get('{any}', 'Controller@page'); 那么像 www.domain.com/post/po-t/some/thing www.domain.com/profile 所以第一个url应该重定向到page函数,第二个url应该重定向到profile函数

在Laravel5.2中,我想将所有未定义的url路由到一个特定的控制器

我正在开发类似CMS的功能,我想要这个东西

Route::get('profile', 'Controller@profile');
Route::get('{any}', 'Controller@page');
那么像

www.domain.com/post/po-t/some/thing

www.domain.com/profile

所以第一个url应该重定向到page函数,第二个url应该重定向到profile函数


基本上,我想要一些关于N-number或参数的想法,因为在页面中,它可以是任意数量的参数,如“www.domain.com/post/po-t/some/thing”

未定义的路由生成404 HTTP状态。您可以在
resources/views/errors
上创建一个
404.blade.php
页面,放置您想要显示的任何视图。无论何时发生404错误,它都会将您重定向到该页面。你不需要做任何其他事情,拉威尔会在幕后处理剩下的事情。

路线

Route::get({any}','Controller@page');

仅适用于以下url

www.domain.com/post

如果你想让它有更多的选择,你必须做另一条路线,比如

Route::get({any}/{any1}','Controller@page');

这将适用于类似于此回调的两个选项

www.domain.com/post/asdfgd

使用

在handle方法中,您可以访问
$request
对象。当找不到路由时,重定向到备用路由。有关获取当前url的选项,请参见

编辑:可以在中找到实现。海报想要保护管理路线:

public function handle($request, Closure $next)
{
    $routeName = Route::currentRouteName();

    // isAdminName would be a quick check. For example,
    // you can check if the string starts with 'admin.'
    if ($this->isAdminName($routeName))
    {
        // If so, he's already accessing an admin path,
        // Just send him on his merry way.
        return $next($request);
    }

    // Otherwise, get the admin route name based on the current route name.
    $adminRouteName = 'admin.' . $routeName;

    // If that route exists, redirect him there.
    if (Route::has($adminRouteName))
    {
        return redirect()->route($adminRouteName);
    }

    // Otherwise, redirect him to the admin home page.
    return redirect('/admin');
}

我知道这一点,但我需要www.domain.com/post/asdfgd的解决方案,因为我们不知道数字或参数是什么,可能您应该尝试可选参数。据我所知,你想要什么,没有解决办法。可选参数接近解决方案<代码>路由::get({a?}/{b?}/{c?}/{d?}/{e?}/{f?},'Controller@page');您希望在中具体执行什么操作Controller@page方法?