如何重定向。 旧网址到新网址。 [Laravel,htaccess]

how to redirect old url to new url.

old url: http://www.example.com/main.php?id=111

new url: http://www.example.com/n/111

my solution is: in routes.php

Route::get('/main.php?id={id}', array('uses' => 'App\Controllers\Front\PageController@oldToNew'));

in action:

public function oldToNew($id)
{
return Redirect::to('http://www.example.com/n/'.$id);
} 

but this code wont work. pls help.

You could make a route that catches all routes that are not in your routes.php. It has to be in the bottom of your routes.php file.

Here you can check if id exists and if the uri contains main.php.

Route::get('{uri}', function($uri)
{
    $id = Input::get('id');

    if(preg_match('/main.php/i', $uri) && isset($id)){
        return Redirect::to('http://www.example.com/n/'.$id);
    }else{
        App::abort(404);
    }

})->where('all', '.*');