全球主机交流论坛

标题: PHP跳转问题。 [打印本页]

作者: 西门小三    时间: 2011-8-2 19:33
标题: PHP跳转问题。
我的博客是wordpress的。为了防止过多垃圾评论的外链分散了网站的权重,我在模板函数加了以下内容。
//comments link redirect
add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
add_filter('comment_text', 'add_redirect_comment_link', 99);
function add_redirect_comment_link($text = ''){
    $text=str_replace('href="', 'href="'.get_option('home').'/?r=', $text);
    $text=str_replace("href='", "href='".get_option('home')."/?r=", $text);
    return $text;
}
add_action('init', 'redirect_comment_link');
function redirect_comment_link(){
    $redirect = $_GET['r'];
    if($redirect){
        if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
            header('HTTP/1.0 301 Moved Permanently');  
            header("Location: $redirect");
            exit;
        }
        else {
            header('HTTP/1.0 301 Moved Permanently');  
            header("Location: http://imwen.org/");
            exit;
        }
    }
}
// end

明眼人一看就看的出,是把链接改成了host/?r=href的形式,然后再做出跳转动作。
原本也没问题,但是博客昨天搬了家,结果出现了以下状况:
http://imwen.org/?r=http://234.com
类似这种,本来应该跳转到http://234.com
但是返回403(因为wordpress永久链接的原因,虽然返回403,但是显示的是网站首页)
http://imwen.org/?r=http://imwen.orghttp://imwen.org/?r=http://imwen.org/54987897/之类的会跳转到http://imwen.org。只会跳转到首页,这个应该算正常,因为上面的代码本身就是这么设置的。
求解,如何设置才能解决?应该是php的配置问题吧。

[ 本帖最后由 西门小三 于 2011-8-2 19:34 编辑 ]
作者: haoqiumi    时间: 2011-8-2 20:23
沙发吧~
作者: nbclare    时间: 2011-8-2 20:27
自己一步步拆吧。。。到处 die();
作者: lemss    时间: 2011-8-2 23:42
看不懂




欢迎光临 全球主机交流论坛 (https://loc.010206.xyz/) Powered by Discuz! X3.4