2010-10-07 188 views
1

我需要幫助決定如何將舊網址重定向到新網址。 在這一刻我有一個像URL重寫後重定向舊網址

myhost.com/viewrecipe.php?id=2

的網址,但我希望他們看起來像

myhost.com/recipes/pear-pie

問題是,該網站已在Google中編入索引。有沒有辦法爲搜索引擎編寫301重定向,將它們從舊類型的Url重定向到新類型?

如果在新的url類型中沒有使用id是不可能實現的,那麼對於搜索引擎來說,其他選項是否可以儘可能平滑地過渡?

P.S.所有這些都是動態網址

回答

0

您可以在包含應用程序的根目錄使用的.htaccess文件

redirect 301 viewrecipe.php?id=2 http://www.myhost.com/recipes/pear-pie 

是的,這將需要所有網址...如果不是你不能試着寫一重寫,但你會在新的友好網址上綁定該ID。

另一種方式將是可以查看在viewrecipie.php ID = 2的代碼是這樣的:?

<?php 
// get the new name dependeind of the id 
$slug = Posts::getByID($id); 

header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.myhost.com/recipes/".$slug); 
?> 

而且最短途徑:

header("Location: http://www.myhost.com/recipes/".$slug",TRUE,301); 
+0

謝謝你,這些都是隻有我想到的方式和你確認他們:) – jusik 2010-10-07 14:35:56

0

您在重寫規則後是否嘗試過[R = 301]?