Please selectSwitch to Mobile Version | Continue to Visit the Desktop Version

 Forgot Password
 Register
View: 435|Reply: 1

htaccess Rewrite SEO URL for Discuz Forum

[Copy Link]
Posted on 2012-07-10 16:49:49 | Show all floors |Read Mode
Files to be modified: 02 ( function_core.php and .htaccess )
1. Open : /source/function/function_core.php
Find
  1. define('DISCUZ_CORE_FUNCTION', true);
Copy Code
Insert below it:

  1.         //Bo dau tieng viet
  2.         function locdau($value)
  3.         {
  4.         //bat dau loc dau
  5.         $locdau_in = array (
  6.         '#(A|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ằ|Ẳ|Ẵ|Ặ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ)#',
  7.         '#(B)#',
  8.         '#(C)#',
  9.         '#(D|Đ|đ)#',
  10.         '#(E|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ)#',
  11.         '#(F)#',
  12.         '#(G)#',
  13.         '#(H)#',
  14.         '#(I|Í|Ì|Ỉ|Ĩ|Ị|í|ì|ỉ|ĩ|ị)#',
  15.         '#(J)#',
  16.         '#(K)#',
  17.         '#(L)#',
  18.         '#(M)#',
  19.         '#(N)#',
  20.         '#(O|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ)#',
  21.         '#(P)#',
  22.         '#(Q)#',
  23.         '#(R)#',
  24.         '#(S)#',
  25.         '#(T)#',
  26.         '#(U|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự)#',
  27.         '#(V)#',
  28.         '#(W)#',
  29.         '#(X)#',
  30.         '#(Ý|Ỳ|Ỷ|Ỹ|Ỵ|Y|ý|ỳ|ỷ|ỹ|ỵ|y)#',
  31.         '#(Z)#',
  32.         "/[^a-zA-Z0-9\-\_]/",
  33.         '#(@)#',
  34.         ) ;
  35.         $locdau_out = array (
  36.         'a',
  37.         'b',
  38.         'c',
  39.         'd',
  40.         'e',
  41.         'f',
  42.         'g',
  43.         'h',
  44.         'i',
  45.         'j',
  46.         'k',
  47.         'l',
  48.         'm',
  49.         'n',
  50.         'o',
  51.         'p',
  52.         'q',
  53.         'r',
  54.         's',
  55.         't',
  56.         'u',
  57.         'v',
  58.         'w',
  59.         'x',
  60.         'y',
  61.         'z',
  62.         '-',
  63.         '-',
  64.         ) ;

  65.         $value = preg_replace($locdau_in, $locdau_out, $value);
  66.         $value = preg_replace('/(-)+/', '-', $value);
  67.         $value = str_replace(array('-quot', '"'), '', $value);
  68.         //ket thuc loc dau
  69.                 return $value;
  70.         }
Copy Code
Find:

  1. function rewriteoutput($type, $returntype, $host) {

  2.     global $_G;

  3.     $fextra = '';

  4.     if($type == 'forum_forumdisplay') {

  5.         list(,,, $fid, $page, $extra) = func_get_args();

  6.         $r = array(

  7.             '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],

  8.             '{page}' => $page ? $page : 1,

  9.             //SEO-URL (c) Vic.0

  10.             '{tenbox}' => locdau(DB::result_first("SELECT name FROM ".DB::table('forum_forum')." WHERE fid='$fid'")),

  11.             //End SEO-URL

  12.         );

  13.     } elseif($type == 'forum_viewthread') {

  14.         list(,,, $tid, $page, $prevpage, $extra) = func_get_args();

  15.         $r = array(

  16.             '{tid}' => $tid,

  17.             '{page}' => $page ? $page : 1,

  18.             '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,

  19.             //SEO-URL (c) Vic.0

  20.             '{tenbai}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('forum_thread')." WHERE tid='$tid'")),

  21.             //End SEO-URL

  22.         );

  23.     } elseif($type == 'home_space') {

  24.         list(,,, $uid, $username, $extra) = func_get_args();

  25.         $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);

  26.         $r = array(

  27.             '{user}' => $uid ? 'uid' : 'username',

  28.             '{value}' => $uid ? $uid : $username,

  29.         );

  30.     } elseif($type == 'home_blog') {

  31.         list(,,, $uid, $blogid, $extra) = func_get_args();

  32.         $r = array(

  33.             '{uid}' => $uid,

  34.             '{blogid}' => $blogid,

  35.         );

  36.     } elseif($type == 'group_group') {

  37.         list(,,, $fid, $page, $extra) = func_get_args();

  38.         $r = array(

  39.             '{fid}' => $fid,

  40.             '{page}' => $page ? $page : 1,

  41.         );

  42.     } elseif($type == 'portal_topic') {

  43.         list(,,, $name, $extra) = func_get_args();

  44.         $r = array(

  45.             '{name}' => $name,

  46.         );

  47.     } elseif($type == 'portal_article') {

  48.         list(,,, $id, $page, $extra) = func_get_args();

  49.         $r = array(

  50.             '{id}' => $id,

  51.             '{page}' => $page ? $page : 1,

  52.         );

  53.     } elseif($type == 'forum_archiver') {

  54.         list(,, $action, $value, $page, $extra) = func_get_args();

  55.         $host = '';

  56.         $r = array(

  57.             '{action}' => $action,

  58.             '{value}' => $value,

  59.         );

  60.         if($page) {

  61.             $fextra = '?page='.$page;

  62.         }

  63.     } elseif($type == 'plugin') {

  64.         list(,, $pluginid, $module,, $param, $extra) = func_get_args();

  65.         $host = '';

  66.         $r = array(

  67.             '{pluginid}' => $pluginid,

  68.             '{module}' => $module,

  69.         );

  70.         if($param) {

  71.             $fextra = '?'.$param;

  72.         }

  73.     }

  74.     $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;

  75.     if(!$returntype) {

  76.         return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';

  77.     } else {

  78.         return $host.$href;

  79.     }

  80. }
Copy Code
Replaced by:

  1. function rewriteoutput($type, $returntype, $host) {
  2.         global $_G;
  3.         $fextra = '';
  4.         if($type == 'forum_forumdisplay') {
  5.                 list(,,, $fid, $page, $extra) = func_get_args();
  6.                 $r = array(
  7.                         '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
  8.                         '{page}' => $page ? $page : 1,
  9.                         '{tenbox}' => locdau(DB::result_first("SELECT name FROM ".DB::table('forum_forum')." WHERE fid='$fid'")),
  10.                 );
  11.         } elseif($type == 'forum_viewthread') {
  12.                 list(,,, $tid, $page, $prevpage, $extra) = func_get_args();
  13.                 $r = array(
  14.                         '{tid}' => $tid,
  15.                         '{page}' => $page ? $page : 1,
  16.                         '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
  17.                         '{tenbai}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('forum_thread')." WHERE tid='$tid'")),
  18.                 );
  19.         } elseif($type == 'home_space') {
  20.                 list(,,, $uid, $username, $extra) = func_get_args();
  21.                 $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
  22.                 $r = array(
  23.                         '{user}' => $uid ? 'uid' : 'username',
  24.                         '{value}' => $uid ? $uid : $username,
  25.                         '{nick}' => DB::result_first("SELECT username FROM ".DB::table('common_member')." WHERE uid='$uid'"),
  26.                 );
  27.         } elseif($type == 'home_blog') {
  28.                 list(,,, $uid, $blogid, $extra) = func_get_args();
  29.                 $r = array(
  30.                         '{uid}' => $uid,
  31.                         '{blogid}' => $blogid,
  32.                         '{tenblog}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('home_blog')." WHERE blogid='$blogid'")),
  33.                 );
  34.         } elseif($type == 'group_group') {
  35.                 list(,,, $fid, $page, $extra) = func_get_args();
  36.                 $r = array(
  37.                         '{fid}' => $fid,
  38.                         '{page}' => $page ? $page : 1,
  39.                 );
  40.         } elseif($type == 'portal_topic') {
  41.                 list(,,, $name, $extra) = func_get_args();
  42.                 $r = array(
  43.                         '{name}' => $name,
  44.                 );
  45.         } elseif($type == 'portal_article') {
  46.                 list(,,, $id, $page, $extra) = func_get_args();
  47.                 $r = array(
  48.                         '{id}' => $id,
  49.                         '{page}' => $page ? $page : 1,
  50.                 );
  51.         } elseif($type == 'forum_archiver') {
  52.                 list(,, $action, $value, $page, $extra) = func_get_args();
  53.                 $host = '';
  54.                 $r = array(
  55.                         '{action}' => $action,
  56.                         '{value}' => $value,
  57.                 );
  58.                 if($page) {
  59.                         $fextra = '?page='.$page;
  60.                 }
  61.         }
  62.         $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
  63.         if(!$returntype) {
  64.                 return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
  65.         } else {
  66.                 return $host.$href;
  67.         }
  68. }
Copy Code
2. Configure .htaccess file like this :

  1. RewriteEngine On

  2. RewriteBase /
  3. RewriteCond %{QUERY_STRING} ^(.*)$
  4. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
  5. RewriteCond %{QUERY_STRING} ^(.*)$
  6. RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
  7. RewriteCond %{QUERY_STRING} ^(.*)$
  8. RewriteRule ^(\w+)/([0-9]+)$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
  9. RewriteCond %{QUERY_STRING} ^(.*)$
  10. RewriteRule ^thread/(.*)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$2&$3&page=$3&%1
  11. RewriteCond %{QUERY_STRING} ^(.*)$
  12. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
  13. RewriteCond %{QUERY_STRING} ^(.*)$
  14. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
  15. RewriteCond %{QUERY_STRING} ^(.*)$
  16. RewriteRule ^blog/{tenblog}-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
  17. RewriteCond %{QUERY_STRING} ^(.*)$
  18. RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
  19. RewriteCond %{QUERY_STRING} ^(.*)$
  20. RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1
Copy Code
3. Login AdminCP --> Global --> SEO --> SEO settings: Enable
4. Upload files & update cache


Reply

Use Props Report

 Thread Author| Posted on 2024-03-07 01:05:36 | Show all floors
This mod still works with Discuz! X 3.5 for Vietnamese title SEO URL
Reply

Use Props Report

You need to log in before you can reply Login | Register

Forum Credit Rules

Close

Editors SelectedPrevious /2 Next

Archiver|Mobile|Darkroom|Privacy|DSC

GMT+7, 2024-03-29 14:26 , Processed in 0.013997 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

Quick Reply Back to Top Return to List