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', '.*');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.