Hello! 欢迎来到盒子萌!

本站自用外链跳转页面go.php源码


avatar
嘉木 2020-04-19 118

结合了张戈提供的go.php

Nginx伪静态设置

网站配置里面加入以下代码

[v_act]#外链跳转伪静态php版本
rewrite ^/go/(.*)$ /go.php?url=$1 last; #注意go.php的实际路径,默认为网站根目录[/v_act]

WordPress替换

在主题的functions.php文件里加入以下代码

//文章外链跳转伪静态版
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\"",$content);
			}
		}
	}
	return $content;
}
add_filter('the_content','link_jump',999);
function link_jump($content){
preg_match_all('//',$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\"",$content);
}
}
}
return $content;
}
外链测试

暂无评论

发表评论