繁体   English   中英

如何在php中重定向URL(旧到新)[laravel,htaccess]

[英]How to redirect URL (Old to New) in php [laravel, htaccess]

最近,我将我的网站corePHP更改为Laravel。 所以我有很多旧的URls,我想将它们重定向为新的URL。

我的旧网址-www.xyz.com/ad_posted.php?title=pure-murra-buffalo-son-bharatpur-1476942104

我想要这样的新网址-www.xyz.com/cat/subcat/pure-murra-buffalo-son-bharatpur-1476942104

我在route.php中有代码

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

    if(preg_match('ad_posted.php?title=', $uri) && isset($title)){
        return Redirect::to('www.xyz.com/cat/subcat/'.$title);
    }
    else{
        App::abort(404);
    }
})->where('all', '.*');

但这没有用。

如果您写的是第一个Route规则,则是捕获所有路由,因此它有可能捕获每个或几乎GET请求。 我将尝试使用具有更具体规则的Route,例如:

Route::get('ad_posted.php', function(){
    $tile = request('title');
    ....
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM