国产美女裸身网站免费观看视频,最新精品国自产拍福利,影音先锋av色噜噜影院,亚洲成av人无码影片

專業(yè)WORDPRESS主題設計制作

WordPress如何將外鏈轉(zhuǎn)內(nèi)鏈?文章外鏈自動轉(zhuǎn)成內(nèi)鏈代碼(wordpress外鏈跳轉(zhuǎn)插件)

發(fā)布于: 2022-11-03

1 外鏈轉(zhuǎn)成內(nèi)鏈優(yōu)勢

  • 2 第 1 步:上傳文件到網(wǎng)站根目錄
    • 2.1 PHP版本
    • 2.2 JS版本
    • 2.3 PHP和JS哪個好?
  • 3 第 2 步:添加代碼到 function.php 文件
    • 3.1 外鏈跳轉(zhuǎn)無加密
    • 3.2 外鏈跳轉(zhuǎn)base64加密【推薦】
  • 4 robots.txt屏蔽蜘蛛

 

WordPress如何將外鏈轉(zhuǎn)內(nèi)鏈?

文章外鏈自動轉(zhuǎn)成內(nèi)鏈代碼

有時候我們因為做谷歌SEO排名,在WordPress網(wǎng)站分享一些被中國網(wǎng)絡封鎖的海外網(wǎng)站或論壇,這樣的鏈接有被墻風險。

innity_adZoneAsync.q.push(function(){innity_adZoneAsync.display(“ee389847678a3a9d1ce9e4ca69200d06″,”96572”,{“target”:”div-ad-innity-96572/0″,”origin”:”MY”});});

所以,我們要將文章中某些外鏈自動轉(zhuǎn)換成內(nèi)鏈。

外鏈轉(zhuǎn)成內(nèi)鏈優(yōu)勢

  • 安全強化:增強對惡意請求的簡單保護;
  • 跳轉(zhuǎn)模式:使用noscript標簽來增加html js跳轉(zhuǎn)模式;
  • 跳轉(zhuǎn)加密:Base64加密的外部鏈,兼容非加密跳轉(zhuǎn);
  • 禁止收錄:添加了禁止搜索引擎蜘蛛收錄和捕獲的META聲明;
  • 禁止使用:禁止其他網(wǎng)站使用我們的跳轉(zhuǎn)頁面。

第 1?步:上傳文件到網(wǎng)站根目錄

WordPress文章外鏈自動轉(zhuǎn)成內(nèi)鏈的代碼,有2個版本:

  1. PHP版本
  2. JS版本

PHP版本

將以下 PHP 代碼保存為 go.php 并上傳到網(wǎng)站根目錄。
















<?
php
if(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取得完整的傳入數(shù)據(jù),然后取得url=之后的所有值,兼容性更好
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"] 


);
//此處可以自定義一些特別的外鏈,不需要可以刪除以下5行
if($t_url=="chenweiliang" ) {
 $t_url="https://www.wordpress



















































































x.com/";
} elseif($t_url=="etufo") {
 $t_url="https://www.etufo.org/";
}
//數(shù)據(jù)處理
if(!empty($t_url)) {
 //判斷取值是否加密
 if ($t_url == base64_encode(base64_decode($t_url))) {
 $t_url = base64_decode($t_url);
 }
 //對取值進行網(wǎng)址校驗和判斷
 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='參數(shù)錯誤,正在返回首頁...';
 }
 }
} else {
 $title = '參數(shù)缺失,正在返回首頁...';
 $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()
{
 //禁止其他網(wǎng)站使用我們的跳轉(zhuǎn)頁面
 var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST'] 























; ?>");
 if (!MyHOST.test(document.referrer)) {
 location.href="http://" + MyHOST;
 }
 location.href="<?php echo $url;?>";
}
//延時1S跳轉(zhuǎn),可自行修改延時時間
setTimeout(link_jump, 1000);
//延時50S關閉跳轉(zhuǎn)頁面,用于文件下載后不會關閉跳轉(zhuǎn)頁的問題
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>

JS版本

將以下 JS 代碼保存為 go.html 并上傳到網(wǎng)站根目錄。















































<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow" />
<script>
//base64加密解密函數(shù)
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))};
//獲取請求參數(shù),支持偽靜態(tài)
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/',''); //注意代碼中的/goto/和跳轉(zhuǎn)地址/goto/保持一致,請記得自行修改!
 }
}
var jump_url = GetQueryString("url");
//若傳入的是base加密數(shù)據(jù),則進行解密處理
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)://)";
//自定義一些跳轉(zhuǎn)字符串,請根據(jù)實際需求自行發(fā)揮
if(jump_url=="chenweiliang") {
 var jump_url="http://news.qtyiliao.cn/";
}
if(jump_url=="etufo") {
 var jump_url="https://www.etufo.org/";
}
//網(wǎng)址校驗
if(jump_url == null || jump_url.toString().length<1 || !jump_url.match(UrlReg)) {
 document.title = '參數(shù)錯誤,正在返回首頁...';
 jump_url = location.origin;
}
//延時執(zhí)行跳轉(zhuǎn)
setTimeout(
function link_jump()
{//非本站域名不允許使用此跳轉(zhuǎn)頁面,請自行修改wordpressx.com為自己的域名

 var MyHOST = new RegExp("wordpressx.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>
<div class="loading">
 <div class="spinner-wrapper">
 <span class="spinner-text">頁面加載中,請稍候...</span>
 <span class="spinner"></span>
 </div>
</div>
</body>
</html>

請注意修改://非本站域名不允許使用此跳轉(zhuǎn)頁面,請自行修改wordpressx.com為自己的域名

innity_adZoneAsync.q.push(function(){innity_adZoneAsync.display(“ee389847678a3a9d1ce9e4ca69200d06″,”96574”,{“target”:”div-ad-innity-96574/0″,”origin”:”MY”});});

PHP和JS哪個好?

PHP 版本和 JS 版本的功能是一樣的,區(qū)別在于:

  • PHP版本是動態(tài)的,略有服務器負載產(chǎn)生;
  • 而JS版本要求瀏覽器支持JS才能正常工作,
  • 但是現(xiàn)在,大多數(shù)瀏覽器都支持它!

注意:如果測試JS版本的跳轉(zhuǎn)代碼無效,就用PHP的跳轉(zhuǎn)代碼。

第 2?步:添加代碼到?function.php?文件

上傳跳轉(zhuǎn)頁面后,接著就是將外鏈跳轉(zhuǎn)代碼,添加到WordPress主題的 function.php 文件里。

article_with_pictures_plugin_1246_permanent_7f2e54494e48f3f75323aee313c93b09.webp

2 選 1 代碼:

  • 1)外鏈跳轉(zhuǎn)無加密
  • 2)外鏈跳轉(zhuǎn)base64加密【推薦】

外鏈跳轉(zhuǎn)無加密











// 外鏈跳轉(zhuǎn)無加密go.html?url
add_filter('the_content','link_to_jump',999);
 function link_to_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&& strpos($val,'wordpressx.com')===false







 && strpos($val,'ufo.org.in')===false && strpos($val,'etufo.org')===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"", "rel="nofollow" target="_blank" href="go.html?url=$val" ",$content);

}
 }
 }
 return $content;
 }

外鏈跳轉(zhuǎn)base64加密【推薦】



















// 外鏈跳轉(zhuǎn)base64加密go.html?url
 add_filter('the_content','link_to_jump',999);
 function link_to_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 && strpos($val,'wordpressx.com')===false && strpos($val,'ufo.org.in')===false && strpos($val,'etufo.org')===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"", "rel="nofollow" target="_blank" href="go.html?url=" .base64_encode($val). "" ",$content);

}
 }
 }
 return $content;
 }

排除指定某個外鏈域名不自動轉(zhuǎn)成內(nèi)鏈(域名白名單):

&& strpos($val,'你的域名')===false

robots.txt屏蔽蜘蛛

為了避免搜索引擎蜘蛛抓取到跳轉(zhuǎn)鏈接,我們可以 robots.txt 文件里,添加禁止搜索引擎蜘蛛抓取的規(guī)則:


User-agent: *
Disallow: /go.html?url=*
Disallow: /go.php?url=*

本文未完,請繼續(xù)看“擴展閱讀”

擴展閱讀:

  • WordPress評論者鏈接如何在新窗口打開跳轉(zhuǎn)?評論外鏈自動轉(zhuǎn)內(nèi)鏈代碼

希望我們網(wǎng)站( http://news.qtyiliao.cn/ ) 分享的《WordPress如何將外鏈轉(zhuǎn)內(nèi)鏈?文章外鏈自動轉(zhuǎn)成內(nèi)鏈代碼》,對您有幫助。

TAG:
WP技術資料 wordpress模板制作、wordpress主題開發(fā)相關知識常見問題總結
MORE
服務電話:
0533-2765967

微信 13280692153