我使用的application/config/routes.php文件重新路由到新的URL查詢到原控制器對象
$route['keyword-library/(:any)/(:any)/(:any)/(:any)/(:any)'] = "library/$1/$2/$3/$4/$5";
$route['keyword-library/(:any)/(:any)/(:any)/(:any)'] = "library/$1/$2/$3/$4";
$route['keyword-library/(:any)/(:any)/(:any)'] = "library/$1/$2/$3";
$route['keyword-library/(:any)/(:any)'] = "library/$1/$2";
$route['keyword-library/(:any)'] = "library/$1";
$route['keyword-library'] = "library";
然後在任何其他代碼之前執行我添加此重新路由老的index.php文件頁面到新頁面。
$uri = $_SERVER['REQUEST_URI'];
if(strpos($uri,'/library') === 0)
{
$expl = explode('/library',$uri);
//array_shift($expl);
$query = implode('',$expl);
$redirect= "https://".$_SERVER['HTTP_HOST'].'/orthomoleculaire-bibliotheek'.$query;
header("Status: 301 Moved Permanently");
header("Location: $redirect");
exit(0);
}
我一直在使用這個的.htaccess嘗試,但由於某些原因,我沒能完成這項工作改道舊網址,因爲變化的變量和可變長度有301新的網址。
如果有人知道更優雅的解決方案,請張貼它,因爲我一直沒有找到。
是的,而不是使用Htaccess,最好是通過路由配置。 – hsuk 2012-07-17 09:47:50
爲什麼不只是''route ['keyword-library /?'] ='library''和'$ route ['keyword-library /(.*)'] ='library/$ 1''而不是那個方法? – 2012-07-17 11:16:00
@KusH,你可以看到我正在使用路由配置。問題是它不能解決搜索引擎的重定向301問題。它只是使現有頁面的別名。谷歌討厭雙倍的內容。 – Tschallacka 2012-07-17 13:18:10