云服务器免费试用

亲测WordPress外链转内链跳转地址为Base64加密地址

服务器知识 0 938

当初由于对 Nginx 服务器比较陌生,根本就不敢根据文中所说的去折腾外链转内链跳转地址为 Base64 加密地址,不过现在终于有胆量去折腾了,而且还一次过成功了,所以今天特意跟大家分享一下。

实测 WordPress 外链转内链跳转地址为 Base64 加密地址b80c93d7d9d931f

导航的环境

  • 使用 PHP 版本的跳转代码;
  • 使用 Nginx 服务器;
  • 原外链跳转地址格式(/go/?url=外链)想改为新的外链格式(/goto/ base64 加密串)。

外链转内链跳转地址为Base64加密地址的详细步骤:

1、将以下跳转代码保存为 index.php,然后在网站根目录新建一个 go 文件夹,并把 index.php 上传到 go 文件夹中。

<?phpif(strlen($_SERVER['REQUEST_URI']) > 255 ||    strpos($_SERVER['REQUEST_URI'], "eval(") ||    strpos($_SERVER['REQUEST_URI'], "base64")) {        @header("HTTP/1.1 414 Request-URI Too Long");        @header("Status: 414 Request-URI Too Long");        @header("Connection: Close");        @exit;}//通过 QUERY_STRING 取得完整的传入数据,然后取得 url=之后的所有值,兼容性更好$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);//此处可以自定义一些特别的外链,不需要可以删除以下 5 行if($t_url=="yigujin" ) {   $t_url="https://www.yigujin.cn";} elseif($t_url=="nana") {   $t_url="https://www.yigujin.cn/nana";}//数据处理if(!empty($t_url)) {    //判断取值是否加密    if ($t_url == base64_encode(base64_decode($t_url))) {        $t_url =  base64_decode($t_url);    }    //对取值进行网址校验和判断    preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches);    if($matches){        $url=$t_url;        $title='页面加载中,请稍候...';    } else {        preg_match('/\./i',$t_url,$matche);        if($matche){            $url='http://'.$t_url;            $title='页面加载中,请稍候...';        } else {            $url = 'http://'.$_SERVER['HTTP_HOST'];            $title='参数错误,正在返回首页...';        }    }} else {    $title = '参数缺失,正在返回首页...';    $url = 'http://'.$_SERVER['HTTP_HOST'];}?><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="robots" content="noindex, nofollow" /><noscript><meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"></noscript><script>function link_jump(){    //禁止其他网站使用我们的跳转页面    var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");    if (!MyHOST.test(document.referrer)) {         location.href="http://" + MyHOST;    }    location.href="<?php echo $url;?>";}//延时 1S 跳转,可自行修改延时时间setTimeout(link_jump, 1000);//延时 50S 关闭跳转页面,用于文件下载后不会关闭跳转页的问题setTimeout(function(){window.opener=null;window.close();}, 50000);</script><title><?php echo $title;?></title><style type="text/css">body{background:#555}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:45%;left:50%;margin-left:-100px;margin-top:2px;color:#000;letter-spacing:1px;font-size:20px;font-family:Arial}.spinner{position:absolute;top:45%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:20px solid rgba(255,0,0,1);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}}</style></head><body><div class="loading">  <div class="spinner-wrapper">    <span class="spinner-text">页面加载中,请稍候...</span>    <span class="spinner"></span>  </div></div></body></html>

其中第行代码中自定义的一些特别外链,这个功能 boke112 认为特别好,因为我们每个站点都或多或少有一些特殊的外链,如果也变成 Base64 加密地址就不好看了,所以此处我们可以多添加几个比较有个性化的外链跳转地址。

2、将以下代码添加到我们的 Nginx 服务器相应配置文件中的location / { 前面,保存配置文件后平滑重启 Nginx 即可。

rewrite ^/goto/(.*)$ /go/?url=$1 last;

3、替换文章原外链跳转地址格式(/go/?url=外链)变更为新的外链格式(/goto/ base64 加密串),我们只需要将以下代码代替主题文件的 functions.php 文件中原先给外部链接加上跳转的代码即可。

//文章外链跳转伪静态版add_filter('the_content','link_jump',999);function link_jump($content){    preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);    if($matches){        foreach($matches[2] as $val){            if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)){            $content=str_replace("href=\"$val\"", "href=\"".home_url()."/goto/".base64_encode($val)."\"",$content);            }        }    }    return $content;}

4、对于评论外链,boke112 认为是不需要改变成 base64 加密串的,保持原汁原味会比较好,所以本站就没有做评论外链跳转的相关操作,所以这步更变评论外链的步骤直接忽略。

5、将下载原外链跳转地址格式(/go/?url=外链)变更为新的外链格式(/goto/ base64 加密串),我们首先将以下代码添加到主题文件 functions.php 文件最后一个?>(记得修改代码中的 boke112.com 为自己的域名)。

// 下载外链跳转function links_nofollow($url) {    if(strpos($url,'://')!==false && strpos($url,'boke112.com')===false && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$url)) {    $url = str_replace($url, home_url()."/goto/".base64_encode($url),$url);         }    return $url;}

然后将主题文件中关于下载链接的地址改为以下代码即可:

<?php echo links_nofollow($url);?>

boke112 导航的下载链接文件就在 inc\file.php(其他主题请自行寻找),然后将四个下载链接地址分别改成上述相对应的代码即可,如将第一个下载链接地址

<?php echo $url1; ?>

改为

<?php echo links_nofollow($url1);?>

至此,boke112 导航的外链及下载地址均变成新的跳转格式(/goto/ base64 加密串),最难得的是原旧跳转格式(/go/?url=外链)依然有效,这个才是值得点赞的。

PS:还记得我们第一步自定义的那些个性化外链吗?到了这里,我们就可以在文章内或侧边栏或广告栏添加相应的链接了。比如我有一条外链是:https://www.yigujin.cn/nana,那么我就可以直接将它改为:https://boke112.com/goto/nana,其他个性化外链同样的方法添加,boke112 认为这个个性化外链也是一个值得点赞的功能。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942@qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 亲测WordPress外链转内链跳转地址为Base64加密地址
本文地址: https://solustack.com/5771.html

相关推荐:

网友留言:

我要评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。