Minimum changes to implement Discuz forum address bar with title Pinyin

Source: Internet
Author: User
Keywords Seo bbs sem discuz

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Problem Description:

Recently have SEO brother begged me to help Discuz forum post title to get to the URL, such as

The post for "Why Flowers So Red", the corresponding address is weishenmohuazheyanghong-t-1-1.html

It's said to help search engine searches.

Problem solving:

I looked at Discuz's PHP code and found that only minor changes were needed to achieve this:

Modern code is as follows:

include/global.func.php modification

function Rewrite_thread ($tid, $page = 0, $prevpage = 0, $extra = ') {

$pinyin = Pinyin (GetThread ($tid));
Return ' <a href= '. $pinyin. ' T. '. $tid. ($page $page: 1). ' -'. ($prevpage &&!is_robot $prevpage: 1). HTML "'. Stripslashes ($extra). > ';

}

function Rewrite_forum ($fid, $page = 0, $extra = ') {

$pinyin = Pinyin (Getforum ($fid));
Return ' <a href= '. $pinyin. ' F '. $fid. ($page $page: 1). HTML "'. Stripslashes ($extra). > ';

}

Add at bottom of file

Include_once ' phpsir_rewrite_pinyin.php ';

New phpsir_rewrite_pinyin.php file content

<?php
Phpsir
function Pinyin ($str, $ishead =0, $isclose =1)
{
Global $pinyins;
Global $charset;

$str = Strip_tags ($STR);

if ($charset = = ' Utf-8 ')
{
$str = Iconv (' utf-8 ', ' GBK ', $str);
}

 //echo $str. <br/> ";
  $RESTR = "";
  $STR = Trim ($STR);
  $slen = strlen ($STR);
 if ($slen <2) return $str;
 if (Count ($pinyins) ==0) {
   $fp = fopen (dirname (__file__). " /pinyin.db "," R ");
  while (!feof ($fp)) {
    $line = Trim (fgets ($fp));
    $pinyins [$line [0]. $line [1]] = substr ($line, 3,strlen ($line)-3);
  }
  fclose ($FP);
 }
 for ($i =0 $i < $slen $i + +) {
  if (ord ($str [$i] >0x80)
  {
     $c = $str [$i]. $str [$i +1];
    $i + +;
   if isset ($pinyins [$c])) {
    if ($ishead ==0) $restr. = $pinyins [$c];
    else $restr. = $pinyins [$c][0];
   }else $restr. = "-";
  }else if (eregi ("[a-z0-9]", $str [$i]) {  $restr. = $str [$i];}
  else{$restr. = "-; }
 
 if ($isclose ==0) unset ($pinyins);
 //echo $restr. <br/>

$a = Array ("/\-{2,}/", "/^\-{1,}/");
$b = Array ("-", "");
$restr = Preg_replace ($a, $b, $restr);

return $restr;
}

function GetThread ($tid)
{
Global $db;
Global $tablepre;
$a = $db->query ("select * from {$tablepre}threads where tid = $tid");
$a = $db->fetch_array ($a);
return $a [' subject '];

}

function Getforum ($FID)
{
Global $db;
Global $tablepre;
$a = $db->query ("select * from {$tablepre}forums where fid = $fid");
$a = $db->fetch_array ($a);
return $a [' name '];

}

End Phpsir
?>

The other thing is to modify. htaccess Join

Rewriterule ^ (. *) f ([0-9]+)-([0-9]+) \.html$ forumdisplay.php?fid=$2&page=$3
Rewriterule ^ (. *) T. ([0-9]+)-([0-9]+) – ([0-9]+) \.html$ viewthread.php?tid=$2&extra=page\%3d$4&page=$3

It

LLYPP QQ 733905 at home


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.