将某个页面重定向到具有相同ID的新页面

时间:2014-12-10 17:19:50

标签: php redirect

我需要将某些页面重定向到具有相同ID的特定页面:

示例:

http://mydomain/?en/273/gallery/711-19-24
http://mydomain/?en/273/gallery/711-19-25
http://mydomain/?en/273/gallery/711-19-32
http://mydomain/?en/273/gallery/others-9000-ID

为:

http://mydomain/newfolder/pics/711-19-24
http://mydomain/newfolder/pics/711-19-25
http://mydomain/newfolder/pics/711-19-32
http://mydomain/newfolder/pics/others-9000-ID

是否有可能使用301 Moved Permanently with php?或者还有其他解决方案吗?

编辑:

我有9000种不同的dinamic ID

3 个答案:

答案 0 :(得分:0)

我想你在某个地方有一个ID变量。您可以使用ID?

为每个页面添加标题
header("location:http://page.com/newfolder/pics/'$id'");

或者只是改变链接而不是相同的想法。

答案 1 :(得分:0)

假设您有一个PHP页面,它首先路由这些,并假设您的示例是准确的:

$queryStringKeys=array_keys($_GET);
if(count($queryStringKeys)==1)
{
    $queryStringParts=explode('/',$queryStringKeys[0]); // gets array of url separated by /

    // check it's the 273/gallery format
    if(strpos($queryStringKeys[0],'273/gallery')>0)
    {
        $lastPart=$queryStringParts[count($queryStringParts)-1];
        Header("HTTP/1.1 301 Moved Permanently");
        Header('Location: /newfolder/pics/'.$lastPart);
        exit;
    }
}

答案 2 :(得分:0)

您可以按\分解网址,然后重定向:

$url = $_SERVER['REQUEST_URI'];
    if( strpos( $url, 'mydomain/' ) !== false ) {
        $exploded_url = explode('/',$url);
        $last = end($exploded_url);
}

Header('Location: /newfolder/pics/'.$last);