出于某种原因,一些人/浏览器重定向到错误的页面。他们被送到:
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]