Redirect To Url เขียนสคริปต์ Link out ให้ Discuz ด้วยต้วคุณเองแบบใหม่รองรับ SEO
แก้ไขล่าสุด Special_kak เมื่อ 2009-7-15 22:09ใครรู้จัก redirect บ้าง อ้าวใครเคยเขียน .htaccess เพื่อสังให้โดนเมน redirect ไปยัง url อื่นๆ บ้าง ผมเคยเห็นแว้บนะ เว็บไหนไม่รู้ การทำงานของสคริปต์ php ตัวนี้คล้ายกับการ redirect ครับ แต่เป็นการใช้ html คือคำสั่ง<html><head>
<meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"/>
</head></html>555+ ง่ายไหมหละ มาดูวิธีกันครับ
สร้างไหล์ php ขึ้นมาด้วย Editplus หรืออะไรก็แล้วแต่ครับ จากนั้นวางโค้ดนี้ลงไป<?php
// we redirect to the website instead of linking directly because we don't want
$url = htmlentities($_GET['url']);
?>
<html><head>
<meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"/>
</head></html>
จะ Save เป็นชื่ออะไรก็ได้นะครับ ตัวอย่างผมบันทึกเป็นชื่อ redirectToUrl.php
จากนั้นอัพไฟล์ redirectToUrl.php ขึ้นไปยังตำแหน่ง root หรือ public_html นั่นเองงับ
จากนั้นเปิดไฟล์ public_html/include/discuzcode.func.php
หาfunction parseurl($url, $text) {
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches;
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
}
}แทนด้วยfunction parseurl($url, $text) {
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches;
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '<a href="redirectToUrl.php?url='.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
return '<a href="redirectToUrl.php?url='.$url.'" target="_blank">'.$text.'</a>';
}
}สังเกต redirectToUrl.php?url=
หาต่อ<a href=\"%s\" target=\"_blank\">%s</a>เปลี่ยนเป็น<a href=\"redirectToUrl.php?url=%s\" target=\"_blank\">%s</a>ตัวอย่าง :: http://www.i7forums.com/redirectToUrl.php?url=http://www.i7forums.com/thread-44-1-1.html ชอนคุณครับ น่าลองมากเลยครับ ไม่ได้อะครับ ทำได้ละครับ ขอบคุณมาก ปรับเวลาให้ช้าลงตรงไหนหรอครับ 6# 038777459
<meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"/> ปรับช้าลงได้ไหม แก้ไงอ่ะบอกทีอ่ะ ไ่ม่เหงช้าเลยอ่ะ content="0; :: 0 คือ 0 วินาทีไงท่าน
ถ้า
content="2; :: 2 คือ 2 วินาทีไงครับ
;P กระทู้นี้ดีมากเลยครับ ขอบคุณนะครับ
หน้า:
[1]
2