本文介绍了如何重定向.旧网址转换为新网址. [Laravel,htacces]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将旧网址重定向到新网址.
how to redirect old url to new url.
旧网址:www.example/main.php?id=111 新网址:www.example/n/111 old url: www.example/main.php?id=111 new url: www.example/n/111我的解决方案是:在routes.php中
my solution is: in routes.php
Route::get('/main.php?id={id}', array('uses' => 'App\Controllers\Front\PageController@oldToNew'));实际情况:
public function oldToNew($id) { return Redirect::to('www.example/n/'.$id); },但是此代码无效.请帮忙.
but this code wont work. pls help.
推荐答案您可以创建一条路由,以捕获不在route.php中的所有路由.它必须在您的routes.php文件的底部.
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.
在这里您可以检查id是否存在以及uri是否包含main.php.
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('www.example/n/'.$id); }else{ App::abort(404); } })->where('all', '.*');更多推荐
如何重定向.旧网址转换为新网址. [Laravel,htacces]
发布评论