Skip to content

rewrite版评论者链者链接重定向

2010 五月 20
by 荒野无灯

mcooo 童鞋要我折腾个rewrite版的链接重定向,前一阵子时间比较忙,没功能折腾,今天抽空弄了下,的确,rewrite版的东东比较好看啦,cool一些,效果就像我的博客现在这样。 :mrgreen:
将以下代码加入当前主题的functions.php中即可。

注意:添加完代码之后 ,一定记得到后台打开一下 “固定链接设置” 。其实就是你什么也不用修改,直接点击打开一下“固定链接” 就 可以了。不然,呵呵,你自己看着办吧。

:mrgreen:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
########START########### 链接重定向处理 by 荒野无灯  http://www.ihacklog.com    ############START#############

function add_comment_link_redirect($text = '')
{
    $text=str_replace('href="http://', 'href="'.get_option('home').'/hacklog_go/', $text);
    $text=str_replace("href='http://", "href='".get_option('home')."/hacklog_go/", $text);
    return $text;
}
add_filter('comment_text', 'add_comment_link_redirect', 99);
add_filter('get_comment_author_link', 'add_comment_link_redirect', 100);

add_filter('query_vars', 'hacklog_comment_redirect_go_query_vars');
function hacklog_comment_redirect_go_query_vars($public_query_vars) {
    $public_query_vars[] = "hacklog_go_url";
    return $public_query_vars;
}



add_filter('generate_rewrite_rules', 'hacklog_comment_redirect_rewrite');
function hacklog_comment_redirect_rewrite($wp_rewrite)
{
    $wp_rewrite->rules = array_merge(array('hacklog_go/(.*)$' => 'index.php?hacklog_go_url=$matches[1]'), $wp_rewrite->rules);
}



add_action('template_redirect', 'hacklog_comment_redirect_go',6);
function hacklog_comment_redirect_go()
{
$url = get_query_var('hacklog_go_url');
$errorPage='http://www.ihacklog.com/error.html';
//$home='http://www.ihacklog.com';
$home=$_SERVER['HTTP_HOST'];
$refer= empty($_SERVER['HTTP_REFERER'])?'http://www.ihacklog.com':$_SERVER['HTTP_REFERER'];

if(!empty($url))
{
        if(false !==strpos($url,'aHR0cDovL') )
            $url=base64_decode($url);
        $url=(!preg_match("/^http\:\/\//i", $url))? "http://".$url:$url;


       if(strpos($refer,$home)===false)  //非本站引用
       {
        header('Location:'.$errorPage);
        exit();
       }
       
        header('Location:'.$url);//直接跳转
         exit();
}
}

######## END ########### 链接重定向处理 by 荒野无灯  http://www.ihacklog.com    ############ END #############

喜欢这篇文章吗?

请订阅本站 RSS feed填写您的邮件地址,订阅我们的精彩内容:,欢迎点击这里捐赠以支持荒野无灯转播到腾讯微博 转播到腾讯微博

作者:荒野无灯
出处:Hacklog【Hacklog】

声明: 本站遵循 署名-非商业性使用-相同方式共享 3.0 共享协议. 转载请注明转自Hacklog【荒野无灯weblog】

本文链接: http://ihacklog.com/?p=3836

15 Responses Post a comment
  1. 三月 4, 2011

    这个功能很有必要!

  2. 八月 2, 2010

    加入当前主题的functions.php中即可??
    我加了就打开不了了~~~首页也打开不了~~~了~ :sad:

  3. 五月 29, 2010

    这样做的话,估计那些垃圾评论者也会自动离开了。

  4. 五月 22, 2010

    好玩 :grin:

  5. 五月 20, 2010

    因为我最近折腾全站的AJAX,点击网址www.a.com/xx.html之后,地址栏上的网址就会加上个“#”变为www.a.com/#/xx.html,,这样访客如果记住像这样的网址,访问只会到www.a.com/上的,所以我就想让它自动跳转到正确的www.a.com/xx.html链接地址上,之前我参照http://ajaxfinder.com/8290/上的做法,可惜不知什么原因就是实现不了, :?:

  6. 五月 20, 2010

    多谢大湿啊,我折腾下先。。。

  7. 五月 20, 2010

    有点意思~

  8. 五月 20, 2010

    我来试试

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <q cite=""> <strong>

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS