如果阵列表包含xyz,于重新定向,其价值(PHP? JS? 不喜欢这里?)

0

的问题

我移动了大约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解决方案是不错的,或者 不喜欢这里,或任何:))

非常感谢你!

1

最好的答案

0

我认为我解决了这个现在就(我也不知道有关就无论是,只是谷歌了甚至更多)。

<IfModule mod_rewrite.c>
RewriteEngine On
RedirectMatch 301 ^/article-cars/ http://NewWebsite.com/new-cars-article
RedirectMatch 301 ^/an-article-dogs/ http://NewWebsite.com/new-dogs-text
RedirectMatch 301 ^/old-text-trees/ http://NewWebsite.com/new-blogcontent-about-trees
</IfModule>

这是好这里吗?

2021-11-21 20:05:20

嗯,它不会的工作? 然后这是"还好",对不对?
arkascha

@arkascha一个工作方案可能仍然是一个不好的解决方案:)它可能导致问题的后面,或者是一个问题,关于安全,等等。
Imre

肯定的是,没有声明是绝对真正的和已知的。 但你怎么能指望别人回答这个吗? 我们知道接下来要什么有关特定情况或未来。 所以我们只能回答一般的和广泛的条款。 重定向请求是可能的,一个正常的事情要做,本身并不突然打开显而易见的安全问题。
arkascha

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................