我有2个同一页面的地址(旧链接和友好的URL链接),两者都很棒!但是我需要将旧链接重定向301:/ instrumenty / show_id /:id到/ instrumenty / show /:id-:slug因为SEO(我得到:来自数据库的2个字段的slug参数)。
我可以在.htaccess的每一页上用一行来做这个...但它并不是一个好主意(我有1000多个这样的页面)。 我试过这样的东西(在routes.php中),但我不知道怎样才能得到我的slug(数据库中的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 :(得分:0)
您不需要访问数据库并在每个重定向链接中插入:slug。如果您只需要搜索引擎优化,那么重定向' / instrumenty / show_id /:id' to' / instruments / 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)
);