- 資訊首頁(yè) > 互聯(lián)網(wǎng) > 主機資訊 >
- 無(wú)需插件為WordPress的文章外鏈轉內鏈且進(jìn)行Base
此教程來(lái)自于pc6a,主機鎮做了精簡(jiǎn)和修改,它可以把自動(dòng)外鏈轉換成“你的網(wǎng)址/go/”。非常方便,而且是php自動(dòng)轉換的,不存儲數據,不需要占用服務(wù)器的空間。絕大部分代碼都是直接引用。小白的教程更適合跟我一樣的純小白使用。
首先打開(kāi)主題文件夾下functions.php文件,按需添加以下代碼
1、文章外鏈轉內鏈:
//文章外鏈跳轉偽靜態(tài)版 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/".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 href='".home_url()."/go/".base64_encode($url)."' rel='nofollow' target='_blank' class='url'>$author</a>"; } else { echo "<a href='$url' target='_blank' class='url'>$author</a>"; } } }
在網(wǎng)站根目錄創(chuàng )建go.html文件,在文件中寫(xiě)入以下代碼:
<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))}; //獲取請求參數,支持偽靜態(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/',''); //注意代碼中的/go/和跳轉地址/go/保持一致,請記得自行修改! } } var jump_url = GetQueryString("url"); //若傳入的是base加密數據,則進(jìn)行解密處理 if( jump_url == base64encode(base64decode(jump_url))) { jump_url = base64decode(jump_url); } //url簡(jiǎn)單正則 var UrlReg = "^((http|https|thunder|qqdl|ed2k|Flashget|qbrowser|ftp|rtsp|mms)://)"; //自定義一些跳轉字符串,請根據實(shí)際需求自行發(fā)揮 if(jump_url=="zhujizhen") { var jump_url="https://www.zhujizhen.com/"; } if(jump_url=="baidu") { var jump_url="https://www.baidu.com/"; } //網(wǎng)址校驗 if(jump_url == null || jump_url.toString().length<1 || !jump_url.match(UrlReg)) { document.title = '參數錯誤,正在返回首頁(yè)...'; jump_url = location.origin; } //延時(shí)執行跳轉 setTimeout( function link_jump() { //非本站域名不允許使用此跳轉頁(yè)面,請自行修改www.zhujizhen.com為自己的域名 var MyHOST = new RegExp("www.zhujizhen.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>頁(yè)面加載中,請稍候...</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">頁(yè)面加載中,請稍候...</span> <span class="spinner"></span> </div> </div> </body> </html>
如果是寶塔直接在網(wǎng)站-設置-偽靜態(tài),最后一行添加下方代碼即可
NGINX代碼:
rewrite ^/go/(.*)$ /go.html?url=$1 last;
Apache代碼:
RewriteRule ^go/(.*)$ /go.html?url=$1 [L]
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站