discuz帖子链接加内部跳转的方法

熊先生 分享 731 次浏览 discuz帖子链接加内部跳转的方法已关闭评论

看到有些网站在发帖加url的时候,会做内部跳转,跳转地址类似:http://www.php2.cc/go.php?url=www.php2.cc,这样可以减少网站的导出链接,下面说下修改方法。

找到文件:source/function/function_discuzcode.php

找到这样一个函数:

[代码]php代码:

01 function parseurl($url, $text, $scheme) {
02
03      global $_G;
04
05      if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
06
07           $url = $matches[0];
08
09           $length = 65;
10
11           if(strlen($url) > $length) {
12
13                $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, -intval($length * 0.3));
14
15           }
16
17           return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url :$url).'" target="_blank">'.$text.'</a>';
18
19      } else {
20
21           $url = substr($url, 1);
22
23           if(substr(strtolower($url), 0, 4) == 'www.') {
24
25                $url = 'http://'.$url;
26
27           }
28
29           $url = !$scheme ? $_G['siteurl'].$url : $url;
30
31           return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
32
33      }
34
35 }

将其修改为:

[代码]php代码:

01 function parseurl($url, $text, $scheme) {
02
03      global $_G;
04
05      if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
06
07           $url = $matches[0];
08
09           $length = 65;
10
11           if(strlen($url) > $length) {
12
13                $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, -intval($length * 0.3));
14
15           }
16
17           return '<a href="http://www.php2.cc/go.php?url='.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
18
19      } else {
20
21           $url = substr($url, 1);
22
23           if(substr(strtolower($url), 0, 4) == 'www.') {
24
25                $url = 'http://'.$url;
26
27           }
28
29           $url = !$scheme ? $_G['siteurl'].$url : $url;
30
31           return '<a href="http://www.php2.cc/go.php?url='.$url.'" target="_blank">'.$text.'</a>';
32
33      }
34
35 }

即可实现。

go.php写法:

[代码]php代码:

1 <?php
2 header('Location: '.$_GET['url']);
3 ?>

 

Go