2014-09-18 59 views
0

我有2個地址在同一頁面(舊鏈接和友好的URL鏈接),並且都很好用!不過,我需要通過301將舊鏈接重定向到/ instrumenty/show_id /:id到/ instrumenty/show /:id-:因爲SEO(我從數據庫的2個字段得到slug參數)。CakePHP 301將舊URL重定向到友好URL

我可以通過.htaccess中的每個頁面執行一行...但這不是一個好主意(我有1000多個這樣的頁面)。 我想這樣的事情(在routes.php文件),但我不知道我怎樣才能讓我的蛞蝓(從數據庫2場)

Router::redirect(
    '/instrumenty/show/:id-:slug', 
    array('controller' => 'instruments', 'action' => 'show_id' /* :id and :slug here? how? */), 
    array('pass' => array('id','slug'), 'status' => '301')  
); 
+0

嘗試的.htaccess,meeeen – ajtamwojtek 2014-09-18 18:19:38

+0

1000線像這樣的: 重定向301/instrumenty/show_id/503/instrumenty /顯示/ 503-MY-大標題 - 塞 真的嗎?它可以以更好的方式完成? – 2014-09-18 18:41:17

回答

0

你並不需要訪問數據庫,並插入:蛞蝓在每重定向鏈接。如果你需要做只是爲了SEO然後重定向「/ instrumenty/show_id /:身份證」到「/儀表/顯示/:身份證」,並插入canonical tag到每個HTML頁面:

echo "<link rel='canonical' href='/instruments/show/$id-$slug' />"; 

在路線,你會碰到這樣的這樣的:

Router::redirect(
    '/instrumenty/show_id/*', 
    array('controller' => 'instruments', 'action' => 'shows'), 
    array('persist' => true) 
);