을 경우 배열/테이블을 포함 xyz 보로 리디렉션 그 값(PHP? JS? htaccess?)

0

질문

이사 약 100 사에서 오래 된 웹사이트에 새로운 하나입니다. 를 만들고 싶은데로 리디렉션에서 옛 사이트 헤더는 경우,그래서 그 이전 URL 을 문서의 될 것이 많이 방문한 방문자가할 수 있어 새로운 URL 을 문서.

그러나,그냥 바꾸는 도메인을 하지 않을 것은 속으로 변경 permalink 의하십시오. 그래서 난 것이요"데이터베이스"(배열?) 는 것을 결정하는 경우는 실제 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솔루션은 너무 잘,또는 htaccess,또는 어떤:))

대단히 감사합니다!

1

최고의 응답

0

나는 해결이 지금 htaccess(나는 아이디어에 대한 htaccess 중 하나,그냥 봤더라도 더 많은).

<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

만,그것은 작동하는가? 그것은"좋아요",right?
arkascha

@arkascha 작업 솔루션을 수 있는 여전히 나쁜 해결책:)그것은 문제가 발생할 수 있습 후,또는 문제에 대한 보안,etc.
Imre

지,아무도 문을 절대적으로 진실하고 알려져 있습니다. 그러나 당신은 어떻게 다른 사람을 기대하는 이야기입니다. 우리가 알고있는 아무것도에 대한 귀사의 특정 상황이나 미래입니다. 그래서 우리는 할 수만 응답에서 일반 및 넓은 용어입니다. 리다이렉션을 요청은,가능한 일상적인 일을 하지 않고 그 자체에 의해 갑자기 열리는 명백한 보안 문제입니다.
arkascha

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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