3

WordPress如何实现内容外链Base64加密外链转内链跳转

 2 years ago
source link: https://www.huhexian.com/9844.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WordPress如何实现内容外链Base64加密外链转内链跳转

青山 2021-11-0816:05:32评论2541字

最近看到不少的小伙伴的博客外链接看不到明链,全部是加密过的。后来咨询了一下几个小伙伴,才知道这个Base64加密方式。下面给大家分享WordPress如何实现内容外链Base64加密外链转内链跳转。

WordPress如何实现内容外链Base64加密外链转内链跳转

第一步:修改Functions.php文件,将下面代码放入文件中。

  1. //自动给文章的外部链接添加nofollow属性
  2. add_filter('the_content','web589_the_content_nofollow',999);
  3. function web589_the_content_nofollow($content){
  4. preg_match_all('/href="(http.*?)"/',$content,$matches);
  5. if($matches){
  6. foreach($matches[1] as $val){
  7. if( strpos($val,home_url())===false )
  8. $content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/links?url=" .base64_encode($val). "\"",$content);
  9. }
  10. }
  11. return $content;
  12. }

第二步:在网站的根目录新建一个文件夹,名称:links,然后再links目录中创建一个index.php文件并将下面的代码放入(把www.huhexian.com改成自己的网址):

  1. <?php
  2. $url = $_GET['url'];
  3. $a = '';
  4. if( $a==$url ) {
  5. $b = "https://www.huhexian.com/";
  6. // echo 'true';
  7. } else {
  8. $b = $url;
  9. $b = base64_decode($b);
  10. }
  11. //Template Name:链接跳转(有过度)
  12. ?>
  13. <html>
  14. <head>
  15. <meta charset=utf-8 />
  16. <meta name="robots" content="nofollow">
  17. <meta http-equiv="refresh" content="0.1;url=<?php echo $b; ?>">
  18. <title>正在为您跳转……</title>
  19. <style>
  20. 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)}}
  21. </style>
  22. </head>
  23. <body>
  24. <div class="loading">
  25. <div class="spinner-wrapper">
  26. <span class="spinner-text">加载中...</span>
  27. <span class="spinner"></span>
  28. </div></div>
  29. </body>
  30. </html>

这种外链方式可以将外部的链接加密成内链,这样一来可以隐藏地址URL,二来可以内链权重不至于流失,两全其美何乐而不为呢。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK