服务器与VPS
促销优惠信息

纯代码wordpress外链转内链,外部网址go跳转并base64加密

查看目录
文章目录隐藏
  1. 一、wordpress外链跳转代码
  2. 二、网站创建go跳转页面
  3. 三、宝塔修改网站伪静态

我们可以看到现在各个大型网站的外部链接都不会直接跳转,而是采用了外链转内链的处理方式,这样一来外链跳转经过中间页过渡降低了本站的跳出率,可以保护网站权重,二来提高了网站安全性,增加一个跳转步骤给网站用户多一层保护。实现这种外链重定向效果的方法有插件法和纯代码方法,本站以前也分享过相关教程,但是今天发现的纯代码wordpress外链转内链方法可以实现外部网址go跳转并实现base64加密,与以前的几个方法有所不同,转载于此,以飨读者。

一、wordpress外链跳转代码

打开当前wordpress主题文件夹下functions.php文件,添加以下代码

1、文章外链转内链:

//文章外链跳转伪静态版
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()."/go.php/".base64_encode($val)."\" rel=\"nofollow\" target=\"_blank\"",$content);
}
}
}
return $content;
}

2、评论外链转内链:

//评论者链接重定向
function commentauthor($comment_ID = 0) {
$url = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );
if ( empty( $url ) || 'http://' == $url ) {
echo $author;
} else {
if (!preg_match(home_url(),$url)) {
echo "<a class="url" href="".home_url()."/go.php/".base64_encode($url)."" target="_blank" rel="nofollow noopener">$author</a>";
} else {
echo "<a class="url" href="$url" target="_blank" rel="noopener">$author</a>";
}
}
}

二、网站创建go跳转页面

在网站根目录创建go.php文件,填入以下外链跳转代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow" />
<script>
//base64加密解密函数
var base64EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var base64DecodeChars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,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,-1,-1,-1,-1,-1,-1,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,-1,-1,-1,-1,-1);function base64encode(str){var out,i,len;var c1,c2,c3;len=str.length;i=0;out="";while(i<len){c1=str.charCodeAt(i++)&255;if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt((c1&3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt((c2&15)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt(((c2&15)<<2)|((c3&192)>>6));out+=base64EncodeChars.charAt(c3&63)}return out}function base64decode(str){var c1,c2,c3,c4;var i,len,out;len=str.length;i=0;out="";while(i<len){do{c1=base64DecodeChars[str.charCodeAt(i++)&255]}while(i<len&&c1==-1);if(c1==-1){break}do{c2=base64DecodeChars[str.charCodeAt(i++)&255]}while(i<len&&c2==-1);if(c2==-1){break}out+=String.fromCharCode((c1<<2)|((c2&48)>>4));do{c3=str.charCodeAt(i++)&255;if(c3==61){return out}c3=base64DecodeChars[c3]}while(i<len&&c3==-1);if(c3==-1){break}out+=String.fromCharCode(((c2&15)<<4)|((c3&60)>>2));do{c4=str.charCodeAt(i++)&255;if(c4==61){return out}c4=base64DecodeChars[c4]}while(i<len&&c4==-1);if(c4==-1){break}out+=String.fromCharCode(((c3&3)<<6)|c4)}return out}function utf16to8(str){var out,i,len,c;out="";len=str.length;for(i=0;i<len;i++){c=str.charCodeAt(i);if((c>=1)&&(c<=127)){out+=str.charAt(i)}else{if(c>2047){out+=String.fromCharCode(224|((c>>12)&15));out+=String.fromCharCode(128|((c>>6)&63));out+=String.fromCharCode(128|((c>>0)&63))}else{out+=String.fromCharCode(192|((c>>6)&31));out+=String.fromCharCode(128|((c>>0)&63))}}}return out}function utf8to16(str){var out,i,len,c;var char2,char3;out="";len=str.length;i=0;while(i<len){c=str.charCodeAt(i++);switch(c>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:out+=str.charAt(i-1);break;case 12:case 13:char2=str.charCodeAt(i++);out+=String.fromCharCode(((c&31)<<6)|(char2&63));break;case 14:char2=str.charCodeAt(i++);char3=str.charCodeAt(i++);out+=String.fromCharCode(((c&15)<<12)|((char2&63)<<6)|((char3&63)<<0));break}}return out}function doit(){var f=document.f;f.output.value=base64encode(utf16to8(f.source.value));f.decode.value=utf8to16(base64decode(f.output.value))};
//获取请求参数,支持伪静态
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=(.*)$");
var r = window.location.search.substr(1).match(reg);
if(r!=null) {
return unescape(r[2]);
} else {
return window.location.pathname.replace('/go.php/',''); //注意代码中的/go.php/和跳转地址/go.php/保持一致,请记得自行修改!
}
}
var jump_url = GetQueryString("url");
//若传入的是base加密数据,则进行解密处理
if( jump_url == base64encode(base64decode(jump_url))) {
jump_url = base64decode(jump_url);
}
//url简单正则
var UrlReg = "^((http|https|thunder|qqdl|ed2k|Flashget|qbrowser|ftp|rtsp|mms)://)";
//自定义一些跳转字符串,请根据实际需求自行发挥
if(jump_url=="mxzi") {
var jump_url="https://www.chukuangren.com/";
}
if(jump_url=="mxzi") {
var jump_url="https://www.chukuangren.com/";
}
//网址校验
if(jump_url == null || jump_url.toString().length<1 || !jump_url.match(UrlReg)) {
document.title = '参数错误,正在返回首页...';
jump_url = location.origin;
}
//延时执行跳转
setTimeout(
function link_jump()
{
//非本站域名不允许使用此跳转页面,请自行修改www.chukuangren.com为自己的域名
var MyHOST = new RegExp("www.chukuangren.com");
if (!MyHOST.test(document.referrer)) {
location.href = "http://" + MyHOST;
return;
}
location.href = jump_url;
}, 1000);
setTimeout(function(){window.opener=null;window.close();}, 50000);
</script>
<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>

三、宝塔修改网站伪静态

如果你的云服务器使用宝塔面板进行管理,则直接在网站-设置-伪静态,最后一行添加下方代码即可。

NGINX代码:

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

Apache代码:

RewriteRule ^go.php/(.*)$ /go.html?url=$1 [L]

啥,你不知道宝塔面板?这么好用的免费服务器管理工具怎可错过,来来来……

免费、安全的服务器运维面板
10850礼包

本外链重定向教程来自于梦兮小站https://www.mtxz.cc/79.html,它可以把外链跳转为“你的网址/go/”的方式,php代码实现转换,不存储数据,不改变数据库,不占用服务器的空间,绝大部分代码都是直接引用。其跳转页效果大概是这样的:

纯代码wordpress外链转内链,外部网址go跳转并base64加密

如果你不喜欢这种效果,而是喜欢那种可以带文字提示的可以参考本站以前教程《仿知乎跳转代码》,不过需要略微懂一点代码知识,可以自己把两段外链转内链代码结合一下。

楚狂人 » 纯代码wordpress外链转内链,外部网址go跳转并base64加密

相关推荐

  • 暂无文章

评论 59

  • (必填)
  • (必填)
  1. #60

    It is appropriate time to make some plans for the future and it's time to be happy.
    I have read this publish and if I may just I desire to recommend you some interesting issues
    or suggestions. Maybe you could write subsequent articles referring to this article.
    I desire to learn more things about it!

  2. #59

    Its like you read my mind! You seem to understand a lot
    approximately this, like you wrote the ebook in it or something.
    I think that you just can do with some % to pressure the message
    house a little bit, however instead of that, that is
    magnificent blog. A fantastic read. I'll certainly be back.

  3. #58

    I am regular visitor, how are you everybody? This piece of writing posted at
    this web site is actually good.

  4. #57

    Hey very nice blog!

  5. #56

    We stumbled over here from a different web page
    and thought I might as well check things out. I like what I see so now i am following you.
    Look forward to looking at your web page for a second time.

  6. #55

    I've been browsing on-line greater than three hours
    nowadays, yet I never discovered any attention-grabbing article like yours.
    It's lovely worth sufficient for me. In my opinion, if all site owners and bloggers made just
    right content material as you did, the web can be a lot more useful than ever before.

  7. #54

    Since the admin of this site is working, no hesitation very shortly it will be famous,
    due to its feature contents.

  8. #53

    Amazing! Its genuinely amazing piece of writing, I have got much clear idea on the topic of from this paragraph.

  9. #52

    Have you ever considered writing an e-book or guest authoring on other blogs?
    I have a blog centered on the same topics you discuss and would really like to have you share some stories/information. I know my subscribers would appreciate
    your work. If you're even remotely interested, feel free to send me
    an e mail.

  10. #51

    Excellent post. I certainly appreciate this site. Stick with it!

  11. #50

    I really like your blog.. very nice colors & theme.
    Did you create this website yourself or did you
    hire someone to do it for you? Plz respond as I'm looking to design my own blog and would like to find out where u got this from.

    appreciate it

  12. #49

    Hi! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing months
    of hard work due to no data backup. Do you have any methods to stop hackers?

  13. #48

    I'm curious to find out what blog system you happen to
    be working with? I'm having some small security problems with my latest website and I
    would like to find something more safeguarded.

    Do you have any recommendations?

  14. #47

    Hi to every , for the reason that I am truly eager of reading this weblog's post to be updated regularly.
    It carries nice information.

  15. #46

    Heya i'm for the primary time here. I came across
    this board and I find It truly helpful & it helped me out a lot.
    I'm hoping to present one thing back and help others such as you
    helped me.

  16. #45

    I simply could not leave your web site prior to suggesting that I really loved the usual info an individual supply on your
    visitors? Is going to be again ceaselessly in order to check out new posts

  17. #44

    Useful information. Lucky me I discovered your site accidentally, and I'm shocked
    why this accident didn't happened earlier! I
    bookmarked it.

  18. #43

    Yesterday, while I was at work, my sister stole my
    iphone and tested to see if it can survive a 30 foot drop, just so she can be a
    youtube sensation. My iPad is now broken and she has
    83 views. I know this is entirely off topic but I had to
    share it with someone!

  19. #42

    If you wish for to get a great deal from this paragraph then you have to apply such methods to your
    won weblog.

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏