WordPress博客内容外链使用Base64加密外链转内链跳转方法
目录
我们在浏览一些博客网站时,里面的一些外链接是看不到明链,都是经过加密的。采用的方式就是 base64 加密,可以将外部的链接加密成内链,接下来就分享 WordPress 博客内容外链 Base64 加密外链转内链跳转方法。
第一步:创建文件夹
首先,在我们网站的根目录下新建一个文件夹,名称:links,然后在 links 目录中创建一个 index.php 文件并将下面的代码放入(把www.mybj123.com改成你自己的网址):
<?php $url = $_GET['url']; $a = ''; if( $a==$url ) { $b = "https://www.mybj123.com/"; // echo 'true'; } else { $b = $url; $b = base64_decode($b); } //Template Name:链接跳转(有过度) ?> <html> <head> <meta charset=utf-8 /> <meta name="robots" content="nofollow"> <meta http-equiv="refresh" content="0.1;url=<?php echo $b; ?>"> <title>正在为您跳转……</title> <style> body{background:#000}.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:41.5%;left:47%;margin:16px 0 0 35px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:9px;font-family:Arial}.spinner{position:absolute;top:40%;left:45%;display:block;margin:0;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-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>
第二步:修改 Functions.php 文件
将下面代码放入我们主题下的 Functions.php 文件中:
//自动给文章的外部链接添加 nofollow 属性 add_filter('the_content','web589_the_content_nofollow',999); function web589_the_content_nofollow($content){ preg_match_all('/href="(http.*?)"/',$content,$matches); if($matches){ foreach($matches[1] as $val){ if( strpos($val,home_url())===false ) $content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val). "\"",$content); } } return $content; }
完成这两步就实现了外部的链接加密成内链,同时外部链接还加上 nofollow 属性,效果如下:
结语
以上外部的链接加密成内链方法,一是可以隐藏地址 URL,二呢可以使内链权重不至于流失,符合 SEO 要求,两全其美,美哉美哉。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » WordPress博客内容外链使用Base64加密外链转内链跳转方法
码云笔记 » WordPress博客内容外链使用Base64加密外链转内链跳转方法