外链本地化(外链重定向跳转)
新建一个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'].'
你现在用的这个怎么弄呢?