StackOverflower
StackOverflower

Reputation: 1097

Laravel 5.1 Redirect With Get Variables

I am trying to figure out this redirect in Laravel 5.1 but I am getting the error

NotFoundHttpException in RouteCollection.php line 161:

This is the redirect I'm trying to achieve

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

to

http://example.com/asdf

This is my current routes file

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

Route::get('/{username}', 'MainController@profile');

and this is my current controller file

public function redirect($username) {
    return Redirect::to('/' . $username, 301);
}

public function profile($username) {
    return view('profile', ['username' => $username]);
}

EDIT: Just to clarify... my redirect() function is never getting called because the url http://example.com/tool/view.php?username=asdf isn't being assigned to a route

Upvotes: 1

Views: 864

Answers (1)

cre8
cre8

Reputation: 13562

You redirect to a route that doesn't exists.At the end of your routfile add something like this: Route:get('{username}', 'YourController@method');

Update

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

}

Upvotes: 2

Related Questions