emlog外链本地化(外链重定向跳转)
[ 2015/01/02, Emlog , 5204阅, 0评 ]

外链本地化(外链重定向跳转)

新建一个php文件并命名为go.php放到网站根目录,go.php中写入以下代码:

<?php
$post = trim($post);
$post = strip_tags($post,""); //清除HTML等代码
$post = ereg_replace("\t","",$post); //去掉制表符号
$post = ereg_replace("\r\n","",$post); //去掉回车换行符号
$post = ereg_replace("\r","",$post); //去掉回车
$post = ereg_replace("\n","",$post); //去掉换行
$post = ereg_replace(" ","",$post); //去掉空格
$post = ereg_replace("'","",$post); //去掉单引号
$go=$_REQUEST["url"];
function if_http($http_url){
	$url=$http_url;
	$preg='|^http://|';
	if(!preg_match($preg,$url)){
		$url='http://'.$url;
	}
	$tz_url=$url;
	return $tz_url;
}
$web=if_http($go);
header("Location:$web");
?>

可以在根目录中打开robot.txt添加以下代码从而拒绝重定向的外部链接被搜索引擎索引到:Disallow: /go.php?url=*

使用方法,以默认模板为例:

module.php中'.$comment['url'].'改为'.BLOG_URL.'go.php?url='.$comment['url'].'

最终效果:https://jiangdesheng.com/go.php?url=https://jiangdesheng.com/

有朋自远方来...评论一下呗O(∩_∩)O