-3

出于某种原因,一些人/浏览器重定向到错误的页面。他们被送到:

http://www.site.com/page.php/http://www.site.com/page.php

代替:

http://www.site.com/page.php

为什么是这样?

附言。我正在使用 MOD_REWRITE。这会有所作为吗?

重定向功能:

function KT_redir($url) {
    $protocol = "http://";
    $server_name = $_SERVER["HTTP_HOST"];
    if ($server_name != '') {
        $protocol = "http://";
        if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == "on")) {
            $protocol = "https://";
        }
        if (preg_match("#^/#", $url)) {
            $url = $protocol.$server_name.$url;
        } else if (!preg_match("#^[a-z]+://#", $url)) {
            $script = KT_getPHP_SELF();
            if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '' && $_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) {
                $script = substr($script, 0, strlen($script) - strlen($_SERVER['PATH_INFO']));
            }
            $url = $protocol.$server_name.(preg_replace("#/[^/]*$#", "/", $script)).$url;
        }
        $url = str_replace(" ","%20",$url);
        if (KT_is_ajax_request()) {
            header("Kt_location: ".$url);
            echo "Redirecting to: " . $url;
        } else {
            header("Location: ".$url);
        }
    }
    exit;
}

MOD_REWRITE

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
4

1 回答 1

0

在您的 之前else if (!preg_match),您需要添加一个 else if 检查以查看是否$url以 a 开头,http如果是,则不要附加任何内容。

于 2012-09-14T23:15:25.567 回答