Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Seo 重写url后重定向旧url_Seo_Friendly Url - Fatal编程技术网

Seo 重写url后重定向旧url

Seo 重写url后重定向旧url,seo,friendly-url,Seo,Friendly Url,我需要帮助决定如何将旧URL重定向到新URL。 在这一刻,我有像这样的网址 myhost.com/viewrecipe.php?id=2 但我想让他们看起来像 myhost.com/recipes/pear-pie 问题是该网站已经在谷歌上建立了索引。有没有办法为搜索引擎编写301重定向,将它们从旧类型的URL重定向到新类型的URL 如果在新的url类型中不使用id是不可能实现的,那么对于搜索引擎来说,还有什么其他选项可以使这种转换尽可能平滑 注意:所有这些都是动态URL您在重写规则后尝试过[R

我需要帮助决定如何将旧URL重定向到新URL。 在这一刻,我有像这样的网址

myhost.com/viewrecipe.php?id=2

但我想让他们看起来像

myhost.com/recipes/pear-pie

问题是该网站已经在谷歌上建立了索引。有没有办法为搜索引擎编写301重定向,将它们从旧类型的URL重定向到新类型的URL

如果在新的url类型中不使用id是不可能实现的,那么对于搜索引擎来说,还有什么其他选项可以使这种转换尽可能平滑


注意:所有这些都是动态URL

您在重写规则后尝试过[R=301]吗?

您可以使用应用程序根目录中的.htaccess文件,其中包含:

redirect 301 viewrecipe.php?id=2 http://www.myhost.com/recipes/pear-pie
是的,这将是您所有的URL所需要的。。。如果没有,你不能尝试写一个重写,但你会在新的搜索引擎优化友好的网址上添加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);