我移动了大约100篇文章从我的旧网站的一个新。 我想创建一个向在旧网站的标题,因此,如果旧网址的一篇文章将被访问,访问应当重新定向到新网址的那篇文章。
然而,仅仅更换领域不会做的伎俩,正如我改变了一篇的文章。 所以 我需要一些"数据库"(与阵?) 这将决定如果实际URL具有重新定向的数据库,如:
// "the old permalink" = "the new permalink"
$urlpermalink["article-cars"] = "http://NewWebsite.com/new-cars-article";
$urlpermalink["an-article-dogs"] = "http://NewWebsite.com/new-dogs-text";
$urlpermalink["old-text-trees"] = "http://NewWebsite.com/new-blogcontent-about-trees";
因此,举例来说,如果一个访问者访问"http://OldWebsite.com/article-cars",他应该重定向到"http://NewWebsite.com/new-cars-article",因为这是如何的数据库/数组说。
所以我可以像这样的东西:
$visitingurl = $_SERVER[REQUEST_URI]; // Getting the URL the visitor is on now
foreach( $urlpermalink as $value ) { // For every entry in the database/array...
if (strpos($visitingurl, $urlpermalink) !== false) { // check if the visitingurl contains that (like "article-cars")
// The visitor is indeed on an old URL which is in the database/array, so let's redirect him to the new URL
header("HTTP/1.1 301 Moved Permanently");
header(url . $_SERVER['QUERY_STRING']);
exit();
}
}
当然这代码是完全错误的,但我们几乎不知道有关 PHP,所以能不能请你帮我解决这个吗? (a JavaScript解决方案是不错的,或者 不喜欢这里,或任何:))
非常感谢你!