簡體   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