全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1018|回复: 3
打印 上一主题 下一主题

[疑问] PHP跳转问题。

[复制链接]
跳转到指定楼层
1#
发表于 2011-8-2 19:33:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的博客是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 编辑 ]
2#
发表于 2011-8-2 20:23:12 | 只看该作者
沙发吧~
3#
发表于 2011-8-2 20:27:07 | 只看该作者
自己一步步拆吧。。。到处 die();
4#
发表于 2011-8-2 23:42:13 | 只看该作者
看不懂
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-14 21:11 , Processed in 0.066668 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表