使用Get变量重定向


Laravel 5.1 Redirect With Get Variables

我试图找出这个重定向在Laravel 5.1,但我得到错误

NotFoundHttpException in RouteCollection.php line 161:

这是我想要实现的重定向

http://example.com/tool/view.php?username=asdf
to
http://example.com/asdf

这是我当前的路由文件

Route::get('/tool/view.php?username={username}', 'MainController@redirect');
Route::get('/{username}', 'MainController@profile');

这是我当前的控制器文件

public function redirect($username) {
    return Redirect::to('/' . $username, 301);
}
public function profile($username) {
    return view('profile', ['username' => $username]);
}

编辑:只是澄清一下……我的redirect()函数从未被调用,因为url http://example.com/tool/view.php?username=asdf没有被分配给路由

你重定向到一个不存在的路由。在routfile的末尾添加这样的内容:Route:get('{username}', 'YourController@method');

更新
Route::get('/tool/view.php', function() {
    return Redirect::to(Input::get('username'), 301);

}